test(bapapi): Print errors to the console

This commit is contained in:
k32 2022-01-26 11:33:41 +01:00
parent bdc6d18589
commit 6f8aa016c3
2 changed files with 24 additions and 16 deletions

View File

@ -37,8 +37,10 @@ end_per_suite(_Config) ->
ok.
t_max_supported_version(_Config) ->
?assertMatch(3, emqx_bpapi:supported_version('i-dont-exist2@localhost', api2)),
?assertMatch(2, emqx_bpapi:supported_version(api2)).
?assertMatch(3, emqx_bpapi:supported_version('fake-node2@localhost', api2)),
?assertMatch(2, emqx_bpapi:supported_version(api2)),
?assertError(_, emqx_bpapi:supported_version('fake-node2@localhost', nonexistent_api)),
?assertError(_, emqx_bpapi:supported_version(nonexistent_api)).
t_announce(Config) ->
meck:new(emqx_bpapi, [passthrough, no_history]),
@ -52,11 +54,11 @@ t_announce(Config) ->
?assertMatch(2, emqx_bpapi:supported_version(api1)).
fake_records() ->
[ #?TAB{key = {'i-dont-exist@localhost', api1}, version = 2}
, #?TAB{key = {'i-dont-exist2@localhost', api1}, version = 2}
[ #?TAB{key = {'fake-node@localhost', api1}, version = 2}
, #?TAB{key = {'fake-node2@localhost', api1}, version = 2}
, #?TAB{key = {?multicall, api1}, version = 2}
, #?TAB{key = {'i-dont-exist@localhost', api2}, version = 2}
, #?TAB{key = {'i-dont-exist2@localhost', api2}, version = 3}
, #?TAB{key = {'fake-node@localhost', api2}, version = 2}
, #?TAB{key = {'fake-node2@localhost', api2}, version = 3}
, #?TAB{key = {?multicall, api2}, version = 2}
].

View File

@ -33,13 +33,19 @@ end_per_suite(_Config) ->
"https://github.com/emqx/emqx/blob/master/apps/emqx/src/bpapi/README.md", []).
t_run_check(_) ->
{ok, OldData} = file:consult(emqx_bpapi_static_checks:versions_file()),
?assert(emqx_bpapi_static_checks:run()),
{ok, NewData} = file:consult(emqx_bpapi_static_checks:versions_file()),
OldData =:= NewData orelse
begin
?CRITICAL("BPAPI versions were changed, but not committed to the repo.\n"
"Run 'make && make static_checks' and then add the changed "
"'bpapi.versions' files to the commit.", []),
error(version_mismatch)
end.
try
{ok, OldData} = file:consult(emqx_bpapi_static_checks:versions_file()),
?assert(emqx_bpapi_static_checks:run()),
{ok, NewData} = file:consult(emqx_bpapi_static_checks:versions_file()),
OldData =:= NewData orelse
begin
?CRITICAL("BPAPI versions were changed, but not committed to the repo.\n"
"Run 'make && make static_checks' and then add the changed "
"'bpapi.versions' files to the commit.", []),
error(version_mismatch)
end
catch
EC:Err:Stack ->
?CRITICAL("Test suite failed: ~p:~p~nStack:~p", [EC, Err, Stack]),
error(tc_failed)
end.