emqx_observer_cli_tests.erl 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. %%--------------------------------------------------------------------
  2. %% Copyright (c) 2022-2023 EMQ Technologies Co., Ltd. All Rights Reserved.
  3. %%
  4. %% Licensed under the Apache License, Version 2.0 (the "License");
  5. %% you may not use this file except in compliance with the License.
  6. %% You may obtain a copy of the License at
  7. %%
  8. %% http://www.apache.org/licenses/LICENSE-2.0
  9. %%
  10. %% Unless required by applicable law or agreed to in writing, software
  11. %% distributed under the License is distributed on an "AS IS" BASIS,
  12. %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. %% See the License for the specific language governing permissions and
  14. %% limitations under the License.
  15. %%--------------------------------------------------------------------
  16. -module(emqx_observer_cli_tests).
  17. -include_lib("eunit/include/eunit.hrl").
  18. start_observer_cli_test() ->
  19. meck:new(observer_cli, [passthrough, no_history, no_link, no_passthrough_cover]),
  20. meck:expect(observer_cli, start, fun() -> ok end),
  21. try
  22. ok = emqx_observer_cli:cmd(["status"])
  23. after
  24. meck:unload(observer_cli)
  25. end.
  26. bin_leak_test() ->
  27. ok = emqx_observer_cli:cmd(["bin_leak"]).
  28. load_observer_cli_test() ->
  29. ok = emqx_observer_cli:cmd(["load", "lists"]).
  30. unknown_command_test() ->
  31. meck_emqx_ctl(),
  32. try
  33. ok = emqx_observer_cli:cmd(dummy),
  34. receive
  35. {usage, [_ | _]} -> ok
  36. end
  37. after
  38. unmeck_emqx_ctl()
  39. end.
  40. meck_emqx_ctl() ->
  41. Pid = self(),
  42. meck:new(emqx_ctl, [passthrough, no_history, no_link, no_passthrough_cover]),
  43. meck:expect(emqx_ctl, usage, fun(Tuples) ->
  44. Pid ! {usage, Tuples},
  45. ok
  46. end).
  47. unmeck_emqx_ctl() ->
  48. meck:unload(emqx_ctl).