fix(syskeeper_bridge): mark syskeeeper as a v2-only action

Fixes https://emqx.atlassian.net/browse/EMQX-11706
This commit is contained in:
Thales Macedo Garitezi 2024-01-10 10:08:17 -03:00
parent a1e86454e1
commit 787f952ad8
3 changed files with 55 additions and 13 deletions

View File

@ -7,14 +7,11 @@
-behaviour(emqx_action_info). -behaviour(emqx_action_info).
-export([ -export([
bridge_v1_type_name/0,
action_type_name/0, action_type_name/0,
connector_type_name/0, connector_type_name/0,
schema_module/0 schema_module/0
]). ]).
bridge_v1_type_name() -> syskeeper_forwarder.
action_type_name() -> syskeeper_forwarder. action_type_name() -> syskeeper_forwarder.
connector_type_name() -> syskeeper_forwarder. connector_type_name() -> syskeeper_forwarder.

View File

@ -38,7 +38,8 @@ groups() ->
t_setup_proxy_via_http_api, t_setup_proxy_via_http_api,
t_setup_forwarder_via_config, t_setup_forwarder_via_config,
t_setup_forwarder_via_http_api, t_setup_forwarder_via_http_api,
t_get_status t_get_status,
t_list_v1_bridges_forwarder
], ],
Write = TCs -- Lifecycle, Write = TCs -- Lifecycle,
BatchingGroups = [{group, with_batch}, {group, without_batch}], BatchingGroups = [{group, with_batch}, {group, without_batch}],
@ -69,17 +70,19 @@ init_per_suite(Config) ->
[ [
emqx_conf, emqx_conf,
emqx_connector, emqx_connector,
emqx_bridge_syskeeper,
emqx_bridge, emqx_bridge,
emqx_bridge_syskeeper emqx_rule_engine,
emqx_management,
{emqx_dashboard, "dashboard.listeners.http { enable = true, bind = 18083 }"}
], ],
#{work_dir => emqx_cth_suite:work_dir(Config)} #{work_dir => emqx_cth_suite:work_dir(Config)}
), ),
emqx_mgmt_api_test_util:init_suite(), {ok, _Api} = emqx_common_test_http:create_default_app(),
[{apps, Apps} | Config]. [{apps, Apps} | Config].
end_per_suite(Config) -> end_per_suite(Config) ->
Apps = ?config(apps, Config), Apps = ?config(apps, Config),
emqx_mgmt_api_test_util:end_suite(),
ok = emqx_cth_suite:stop(Apps), ok = emqx_cth_suite:stop(Apps),
ok. ok.
@ -189,7 +192,7 @@ create_bridge(Type, Name, Conf) ->
delete_bridge(Type, Name) -> delete_bridge(Type, Name) ->
emqx_bridge_v2:remove(Type, Name). emqx_bridge_v2:remove(Type, Name).
create_both_bridge(Config) -> create_both_bridges(Config) ->
{ProxyName, ProxyConf} = syskeeper_proxy_config(Config), {ProxyName, ProxyConf} = syskeeper_proxy_config(Config),
{ConnectorName, ConnectorConf} = syskeeper_connector_config(Config), {ConnectorName, ConnectorConf} = syskeeper_connector_config(Config),
{Name, Conf} = syskeeper_config(Config), {Name, Conf} = syskeeper_config(Config),
@ -203,7 +206,8 @@ create_both_bridge(Config) ->
create_connectors(syskeeper_forwarder, ConnectorName, ConnectorConf) create_connectors(syskeeper_forwarder, ConnectorName, ConnectorConf)
), ),
timer:sleep(1000), timer:sleep(1000),
?assertMatch({ok, _}, create_bridge(syskeeper_forwarder, Name, Conf)). ?assertMatch({ok, _}, create_bridge(syskeeper_forwarder, Name, Conf)),
Name.
create_bridge_http(Params) -> create_bridge_http(Params) ->
call_create_http("actions", Params). call_create_http("actions", Params).
@ -334,7 +338,7 @@ t_setup_forwarder_via_http_api(Config) ->
). ).
t_get_status(Config) -> t_get_status(Config) ->
create_both_bridge(Config), create_both_bridges(Config),
?assertMatch( ?assertMatch(
#{status := connected}, emqx_bridge_v2:health_check(syskeeper_forwarder, ?SYSKEEPER_NAME) #{status := connected}, emqx_bridge_v2:health_check(syskeeper_forwarder, ?SYSKEEPER_NAME)
), ),
@ -349,7 +353,7 @@ t_get_status(Config) ->
). ).
t_write_failure(Config) -> t_write_failure(Config) ->
create_both_bridge(Config), create_both_bridges(Config),
delete_connectors(syskeeper_proxy, ?SYSKEEPER_PROXY_NAME), delete_connectors(syskeeper_proxy, ?SYSKEEPER_PROXY_NAME),
SentData = make_message(), SentData = make_message(),
Result = Result =
@ -361,7 +365,7 @@ t_write_failure(Config) ->
?assertMatch({{error, {resource_error, _}}, _}, Result). ?assertMatch({{error, {resource_error, _}}, _}, Result).
t_invalid_data(Config) -> t_invalid_data(Config) ->
create_both_bridge(Config), create_both_bridges(Config),
{_, {ok, #{result := Result}}} = {_, {ok, #{result := Result}}} =
?wait_async_action( ?wait_async_action(
send_message(Config, #{}), send_message(Config, #{}),
@ -372,7 +376,7 @@ t_invalid_data(Config) ->
t_forward(Config) -> t_forward(Config) ->
emqx_broker:subscribe(?TOPIC), emqx_broker:subscribe(?TOPIC),
create_both_bridge(Config), create_both_bridges(Config),
SentData = make_message(), SentData = make_message(),
{_, {ok, #{result := _Result}}} = {_, {ok, #{result := _Result}}} =
?wait_async_action( ?wait_async_action(
@ -387,3 +391,43 @@ t_forward(Config) ->
), ),
emqx_broker:unsubscribe(?TOPIC), emqx_broker:unsubscribe(?TOPIC),
ok. ok.
t_list_v1_bridges_forwarder(Config) ->
?check_trace(
begin
Name = create_both_bridges(Config),
?assertMatch(
{ok, {{_, 200, _}, _, []}}, emqx_bridge_v2_testlib:list_bridges_http_api_v1()
),
?assertMatch(
{ok, {{_, 200, _}, _, [_]}}, emqx_bridge_v2_testlib:list_actions_http_api()
),
?assertMatch(
{ok, {{_, 200, _}, _, [_, _]}}, emqx_bridge_v2_testlib:list_connectors_http_api()
),
RuleTopic = <<"t/c">>,
{ok, #{<<"id">> := RuleId0}} =
emqx_bridge_v2_testlib:create_rule_and_action_http(
<<"syskeeper_forwarder">>,
RuleTopic,
[{bridge_name, Name} | Config],
#{overrides => #{enable => true}}
),
?assert(emqx_bridge_v2_testlib:is_rule_enabled(RuleId0)),
?assertMatch(
{ok, {{_, 200, _}, _, _}}, emqx_bridge_v2_testlib:enable_rule_http(RuleId0)
),
?assert(emqx_bridge_v2_testlib:is_rule_enabled(RuleId0)),
?assertMatch(
{error, no_v1_equivalent},
emqx_action_info:bridge_v1_type_name(syskeeper_forwarder)
),
ok
end,
[]
),
ok.

View File

@ -0,0 +1 @@
Fixed a crash when listing bridges via `GET /bridges` when a Syskeeper Forwarder bridge exists.