emqx_plugins_SUITE.erl 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. %%--------------------------------------------------------------------
  2. %% Copyright (c) 2019 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_plugins_SUITE).
  17. -compile(export_all).
  18. -compile(nowarn_export_all).
  19. -include_lib("eunit/include/eunit.hrl").
  20. all() -> emqx_ct:all(?MODULE).
  21. init_per_suite(Config) ->
  22. %% Compile extra plugin code
  23. DataPath = proplists:get_value(data_dir, Config),
  24. AppPath = filename:join([DataPath, "emqx_mini_plugin"]),
  25. Cmd = lists:flatten(io_lib:format("cd ~s && make", [AppPath])),
  26. ct:pal("Executing ~s~n", [Cmd]),
  27. ct:pal("~n ~s~n", [os:cmd(Cmd)]),
  28. code:add_path(filename:join([AppPath, "_build", "default", "lib", "emqx_mini_plugin", "ebin"])),
  29. put(loaded_file, filename:join([DataPath, "loaded_plugins"])),
  30. emqx_ct_helpers:start_apps([], fun set_sepecial_cfg/1),
  31. Config.
  32. set_sepecial_cfg(_) ->
  33. ExpandPath = filename:dirname(code:lib_dir(emqx_mini_plugin)),
  34. application:set_env(emqx, plugins_loaded_file, get(loaded_file)),
  35. application:set_env(emqx, expand_plugins_dir, ExpandPath),
  36. ok.
  37. end_per_suite(_Config) ->
  38. emqx_ct_helpers:stop_apps([]).
  39. t_load(_) ->
  40. {error, load_app_fail} = emqx_plugins:load_expand_plugin("./not_existed_path/"),
  41. {error, not_started} = emqx_plugins:unload(emqx_mini_plugin),
  42. {ok, _} = emqx_plugins:load(emqx_mini_plugin),
  43. ok = emqx_plugins:unload(emqx_mini_plugin).