emqx_bpapi_SUITE.erl 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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_bpapi_SUITE).
  17. -compile(export_all).
  18. -compile(nowarn_export_all).
  19. -include_lib("common_test/include/ct.hrl").
  20. -include_lib("stdlib/include/assert.hrl").
  21. -include_lib("emqx/src/bpapi/emqx_bpapi.hrl").
  22. all() -> emqx_common_test_helpers:all(?MODULE).
  23. init_per_suite(Config) ->
  24. emqx_common_test_helpers:start_apps([emqx]),
  25. [mnesia:dirty_write(Rec) || Rec <- fake_records()],
  26. Config.
  27. end_per_suite(_Config) ->
  28. meck:unload(),
  29. [mnesia:dirty_delete({?TAB, Key}) || #?TAB{key = Key} <- fake_records()],
  30. emqx_bpapi:announce(emqx),
  31. emqx_common_test_helpers:stop_apps([emqx]),
  32. ok.
  33. t_max_supported_version(_Config) ->
  34. ?assertMatch(3, emqx_bpapi:supported_version('fake-node2@localhost', api2)),
  35. ?assertMatch(2, emqx_bpapi:supported_version(api2)),
  36. ?assertMatch(undefined, emqx_bpapi:supported_version('fake-node2@localhost', nonexistent_api)),
  37. ?assertError(_, emqx_bpapi:supported_version(nonexistent_api)).
  38. t_announce(Config) ->
  39. meck:new(emqx_bpapi, [passthrough, no_history]),
  40. Filename = filename:join(?config(data_dir, Config), "test.versions"),
  41. meck:expect(emqx_bpapi, versions_file, fun(_) -> Filename end),
  42. ?assertMatch(ok, emqx_bpapi:announce(emqx)),
  43. timer:sleep(100),
  44. ?assertMatch(4, emqx_bpapi:supported_version(node(), api2)),
  45. ?assertMatch(2, emqx_bpapi:supported_version(node(), api1)),
  46. ?assertMatch(2, emqx_bpapi:supported_version(api2)),
  47. ?assertMatch(2, emqx_bpapi:supported_version(api1)).
  48. fake_records() ->
  49. [
  50. #?TAB{key = {'fake-node@localhost', api1}, version = 2},
  51. #?TAB{key = {'fake-node2@localhost', api1}, version = 2},
  52. #?TAB{key = {?multicall, api1}, version = 2},
  53. #?TAB{key = {'fake-node@localhost', api2}, version = 2},
  54. #?TAB{key = {'fake-node2@localhost', api2}, version = 3},
  55. #?TAB{key = {?multicall, api2}, version = 2}
  56. ].