fix(bpapi): Return undefined for unknown API on the node

This commit is contained in:
ieQu1 2022-09-05 12:28:19 +02:00
parent d4785553b9
commit c2d03838e2
2 changed files with 6 additions and 3 deletions

View File

@ -69,9 +69,12 @@ start() ->
announce(emqx).
%% @doc Get maximum version of the backplane API supported by the node
-spec supported_version(node(), api()) -> api_version().
-spec supported_version(node(), api()) -> api_version() | undefined.
supported_version(Node, API) ->
ets:lookup_element(?TAB, {Node, API}, #?TAB.version).
case ets:lookup(?TAB, {Node, API}) of
[#?TAB{version = V}] -> V;
[] -> undefined
end.
%% @doc Get maximum version of the backplane API supported by the
%% entire cluster

View File

@ -40,7 +40,7 @@ end_per_suite(_Config) ->
t_max_supported_version(_Config) ->
?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)),
?assertMatch(undefined, emqx_bpapi:supported_version('fake-node2@localhost', nonexistent_api)),
?assertError(_, emqx_bpapi:supported_version(nonexistent_api)).
t_announce(Config) ->