emqx_eviction_agent_api_SUITE.erl 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. %%--------------------------------------------------------------------
  2. %% Copyright (c) 2022-2024 EMQ Technologies Co., Ltd. All Rights Reserved.
  3. %%--------------------------------------------------------------------
  4. -module(emqx_eviction_agent_api_SUITE).
  5. -compile(export_all).
  6. -compile(nowarn_export_all).
  7. -include_lib("eunit/include/eunit.hrl").
  8. -include_lib("common_test/include/ct.hrl").
  9. -import(
  10. emqx_mgmt_api_test_util,
  11. [
  12. request_api/2,
  13. uri/1
  14. ]
  15. ).
  16. all() ->
  17. emqx_common_test_helpers:all(?MODULE).
  18. init_per_suite(Config) ->
  19. Apps = emqx_cth_suite:start(
  20. [
  21. emqx,
  22. emqx_eviction_agent,
  23. emqx_management,
  24. {emqx_dashboard, "dashboard.listeners.http { enable = true, bind = 18083 }"}
  25. ],
  26. #{
  27. work_dir => emqx_cth_suite:work_dir(Config)
  28. }
  29. ),
  30. _ = emqx_common_test_http:create_default_app(),
  31. [{apps, Apps} | Config].
  32. end_per_suite(Config) ->
  33. emqx_common_test_http:delete_default_app(),
  34. emqx_cth_suite:stop(?config(apps, Config)).
  35. %%--------------------------------------------------------------------
  36. %% Tests
  37. %%--------------------------------------------------------------------
  38. t_status(_Config) ->
  39. ?assertMatch(
  40. {ok, #{<<"status">> := <<"disabled">>}},
  41. api_get(["node_eviction", "status"])
  42. ),
  43. ok = emqx_eviction_agent:enable(apitest, undefined),
  44. ?assertMatch(
  45. {ok, #{
  46. <<"status">> := <<"enabled">>,
  47. <<"stats">> := #{}
  48. }},
  49. api_get(["node_eviction", "status"])
  50. ),
  51. ok = emqx_eviction_agent:disable(apitest),
  52. ?assertMatch(
  53. {ok, #{<<"status">> := <<"disabled">>}},
  54. api_get(["node_eviction", "status"])
  55. ).
  56. %%--------------------------------------------------------------------
  57. %% Helpers
  58. %%--------------------------------------------------------------------
  59. api_get(Path) ->
  60. case request_api(get, uri(Path)) of
  61. {ok, ResponseBody} ->
  62. {ok, jiffy:decode(list_to_binary(ResponseBody), [return_maps])};
  63. {error, _} = Error ->
  64. Error
  65. end.