emqx_bpapi_SUITE.erl 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. %%--------------------------------------------------------------------
  2. %% Copyright (c) 2022-2024 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. Apps = emqx_cth_suite:start([emqx], #{work_dir => emqx_cth_suite:work_dir(Config)}),
  25. [mnesia:dirty_write(Rec) || Rec <- fake_records()],
  26. [{apps, Apps} | Config].
  27. end_per_suite(Config) ->
  28. meck:unload(),
  29. emqx_cth_suite:stop(?config(apps, Config)).
  30. t_max_supported_version(_Config) ->
  31. ?assertMatch(3, emqx_bpapi:supported_version('fake-node2@localhost', api2)),
  32. ?assertMatch(2, emqx_bpapi:supported_version(api2)),
  33. ?assertMatch(undefined, emqx_bpapi:supported_version('fake-node2@localhost', nonexistent_api)),
  34. ?assertError(_, emqx_bpapi:supported_version(nonexistent_api)).
  35. t_announce(Config) ->
  36. meck:new(emqx_bpapi, [passthrough, no_history]),
  37. Filename = filename:join(?config(data_dir, Config), "test.versions"),
  38. meck:expect(emqx_bpapi, versions_file, fun(_) -> Filename end),
  39. FakeNode = 'fake-node@127.0.0.1',
  40. ?assertMatch(ok, emqx_bpapi:announce(FakeNode, emqx)),
  41. timer:sleep(100),
  42. ?assertMatch(4, emqx_bpapi:supported_version(FakeNode, api2)),
  43. ?assertMatch(2, emqx_bpapi:supported_version(FakeNode, api1)),
  44. ?assertMatch(2, emqx_bpapi:supported_version(api2)),
  45. ?assertMatch(2, emqx_bpapi:supported_version(api1)).
  46. fake_records() ->
  47. [
  48. #?TAB{key = {'fake-node@localhost', api1}, version = 2},
  49. #?TAB{key = {'fake-node2@localhost', api1}, version = 2},
  50. #?TAB{key = {?multicall, api1}, version = 2},
  51. #?TAB{key = {'fake-node@localhost', api2}, version = 2},
  52. #?TAB{key = {'fake-node2@localhost', api2}, version = 3},
  53. #?TAB{key = {?multicall, api2}, version = 2}
  54. ].