test: fix broken tests

This commit is contained in:
Thales Macedo Garitezi 2023-12-19 18:34:10 -03:00
parent cc34660ab9
commit 697c8f5ee1
5 changed files with 30 additions and 24 deletions

View File

@ -347,14 +347,16 @@ lookup(Type, Name, RawConf) ->
}} }}
end. end.
get_metrics(Type, Name) -> get_metrics(ActionType, Name) ->
case emqx_bridge_v2:is_bridge_v2_type(Type) of case emqx_bridge_v2:is_bridge_v2_type(ActionType) of
true -> true ->
case emqx_bridge_v2:bridge_v1_is_valid(Type, Name) of case emqx_bridge_v2:bridge_v1_is_valid(ActionType, Name) of
true -> true ->
BridgeV2Type = emqx_bridge_v2:bridge_v2_type_to_connector_type(Type), BridgeV2Type = emqx_bridge_v2:bridge_v2_type_to_connector_type(ActionType),
try try
ConfRootKey = emqx_bridge_v2:get_conf_root_key_if_only_one(Type, Name), ConfRootKey = emqx_bridge_v2:get_conf_root_key_if_only_one(
ActionType, Name
),
emqx_bridge_v2:get_metrics(ConfRootKey, BridgeV2Type, Name) emqx_bridge_v2:get_metrics(ConfRootKey, BridgeV2Type, Name)
catch catch
error:Reason -> error:Reason ->
@ -364,7 +366,7 @@ get_metrics(Type, Name) ->
{error, not_bridge_v1_compatible} {error, not_bridge_v1_compatible}
end; end;
false -> false ->
emqx_resource:get_metrics(emqx_bridge_resource:resource_id(Type, Name)) emqx_resource:get_metrics(emqx_bridge_resource:resource_id(ActionType, Name))
end. end.
maybe_upgrade(mqtt, Config) -> maybe_upgrade(mqtt, Config) ->

View File

@ -46,6 +46,7 @@
%% The remove/2 function is only for internal use as it may create %% The remove/2 function is only for internal use as it may create
%% rules with broken dependencies %% rules with broken dependencies
remove/2, remove/2,
remove/3,
%% The following is the remove function that is called by the HTTP API %% The following is the remove function that is called by the HTTP API
%% It also checks for rule action dependencies and optionally removes %% It also checks for rule action dependencies and optionally removes
%% them %% them

View File

@ -188,18 +188,7 @@ end_per_testcase(_, Config) ->
ok. ok.
clear_resources() -> clear_resources() ->
lists:foreach( emqx_bridge_v2_testlib:delete_all_bridges_and_connectors(),
fun(#{type := Type, name := Name}) ->
ok = emqx_bridge_v2:remove(Type, Name)
end,
emqx_bridge_v2:list()
),
lists:foreach(
fun(#{type := Type, name := Name}) ->
ok = emqx_connector:remove(Type, Name)
end,
emqx_connector:list()
),
lists:foreach( lists:foreach(
fun(#{type := Type, name := Name}) -> fun(#{type := Type, name := Name}) ->
ok = emqx_bridge:remove(Type, Name) ok = emqx_bridge:remove(Type, Name)
@ -1026,9 +1015,11 @@ t_with_redact_update(Config) ->
BridgeConf = emqx_utils:redact(Template), BridgeConf = emqx_utils:redact(Template),
BridgeID = emqx_bridge_resource:bridge_id(Type, Name), BridgeID = emqx_bridge_resource:bridge_id(Type, Name),
{ok, 200, _} = request(put, uri(["bridges", BridgeID]), BridgeConf, Config), {ok, 200, _} = request(put, uri(["bridges", BridgeID]), BridgeConf, Config),
%% bridge is migrated after creation
ConfigRootKey = connectors,
?assertEqual( ?assertEqual(
Password, Password,
get_raw_config([bridges, Type, Name, password], Config) get_raw_config([ConfigRootKey, Type, Name, password], Config)
), ),
%% probe with new password; should not be considered redacted %% probe with new password; should not be considered redacted

View File

@ -96,9 +96,15 @@ delete_all_bridges_and_connectors() ->
delete_all_bridges() -> delete_all_bridges() ->
lists:foreach( lists:foreach(
fun(#{name := Name, type := Type}) -> fun(#{name := Name, type := Type}) ->
emqx_bridge_v2:remove(Type, Name) emqx_bridge_v2:remove(actions, Type, Name)
end, end,
emqx_bridge_v2:list() emqx_bridge_v2:list(actions)
),
lists:foreach(
fun(#{name := Name, type := Type}) ->
emqx_bridge_v2:remove(sources, Type, Name)
end,
emqx_bridge_v2:list(sources)
). ).
delete_all_connectors() -> delete_all_connectors() ->

View File

@ -244,6 +244,12 @@ parse_http_request_assertive(ReqStr0) ->
%% Helper functions %% Helper functions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
get_metrics(Name) ->
%% Note: `emqx_bridge:get_metrics/2' is currently *only* called in prod by
%% `emqx_bridge_api:lookup_from_local_node' with an action (not v1 bridge) type.
Type = <<"http">>,
emqx_bridge:get_metrics(Type, Name).
bridge_async_config(#{port := Port} = Config) -> bridge_async_config(#{port := Port} = Config) ->
Type = maps:get(type, Config, ?BRIDGE_TYPE), Type = maps:get(type, Config, ?BRIDGE_TYPE),
Name = maps:get(name, Config, ?BRIDGE_NAME), Name = maps:get(name, Config, ?BRIDGE_NAME),
@ -570,7 +576,7 @@ t_path_not_found(Config) ->
success := 0 success := 0
} }
}, },
emqx_bridge:get_metrics(?BRIDGE_TYPE, ?BRIDGE_NAME) get_metrics(?BRIDGE_NAME)
) )
), ),
ok ok
@ -611,7 +617,7 @@ t_too_many_requests(Config) ->
success := 1 success := 1
} }
}, },
emqx_bridge:get_metrics(?BRIDGE_TYPE, ?BRIDGE_NAME) get_metrics(?BRIDGE_NAME)
) )
), ),
ok ok
@ -654,7 +660,7 @@ t_rule_action_expired(Config) ->
dropped := 1 dropped := 1
} }
}, },
emqx_bridge:get_metrics(?BRIDGE_TYPE, ?BRIDGE_NAME) get_metrics(?BRIDGE_NAME)
) )
), ),
?retry( ?retry(