Merge pull request #12604 from thalesmg/test-gcp-consu-tm-m-20240227
test(gcp_pubsub_consumer): add test case for updating topic when there is a topic mapping
This commit is contained in:
commit
f1e9da9048
|
@ -312,7 +312,7 @@ get_bridge_api(BridgeKind, BridgeType, BridgeName) ->
|
|||
Path = emqx_mgmt_api_test_util:api_path([Root, BridgeId]),
|
||||
ct:pal("get bridge ~p (via http)", [{BridgeKind, BridgeType, BridgeName}]),
|
||||
Res = request(get, Path, Params),
|
||||
ct:pal("get bridge ~p result: ~p", [{BridgeType, BridgeName}, Res]),
|
||||
ct:pal("get bridge ~p result: ~p", [{BridgeKind, BridgeType, BridgeName}, Res]),
|
||||
Res.
|
||||
|
||||
create_bridge_api(Config) ->
|
||||
|
|
|
@ -33,6 +33,7 @@ all() ->
|
|||
emqx_common_test_helpers:all(?MODULE).
|
||||
|
||||
init_per_suite(Config) ->
|
||||
emqx_common_test_helpers:clear_screen(),
|
||||
GCPEmulatorHost = os:getenv("GCP_EMULATOR_HOST", "toxiproxy"),
|
||||
GCPEmulatorPortStr = os:getenv("GCP_EMULATOR_PORT", "8085"),
|
||||
GCPEmulatorPort = list_to_integer(GCPEmulatorPortStr),
|
||||
|
|
|
@ -208,3 +208,48 @@ t_consume(Config) ->
|
|||
}
|
||||
),
|
||||
ok.
|
||||
|
||||
t_update_topic(Config) ->
|
||||
%% Tests that, if a bridge originally has the legacy field `topic_mapping' filled in
|
||||
%% and later is updated using v2 APIs, then the legacy field is cleared and the new
|
||||
%% `topic' field is used.
|
||||
ConnectorConfig = ?config(connector_config, Config),
|
||||
SourceConfig = ?config(source_config, Config),
|
||||
Name = ?config(source_name, Config),
|
||||
V1Config0 = emqx_action_info:connector_action_config_to_bridge_v1_config(
|
||||
?SOURCE_TYPE_BIN,
|
||||
ConnectorConfig,
|
||||
SourceConfig
|
||||
),
|
||||
V1Config = emqx_utils_maps:deep_put(
|
||||
[<<"consumer">>, <<"topic_mapping">>],
|
||||
V1Config0,
|
||||
[
|
||||
#{
|
||||
<<"pubsub_topic">> => <<"old_topic">>,
|
||||
<<"mqtt_topic">> => <<"">>,
|
||||
<<"qos">> => 2,
|
||||
<<"payload_template">> => <<"template">>
|
||||
}
|
||||
]
|
||||
),
|
||||
%% Note: using v1 API
|
||||
{ok, {{_, 201, _}, _, _}} = emqx_bridge_testlib:create_bridge_api(
|
||||
?SOURCE_TYPE_BIN,
|
||||
Name,
|
||||
V1Config
|
||||
),
|
||||
?assertMatch(
|
||||
{ok, {{_, 200, _}, _, #{<<"parameters">> := #{<<"topic">> := <<"old_topic">>}}}},
|
||||
emqx_bridge_v2_testlib:get_source_api(?SOURCE_TYPE_BIN, Name)
|
||||
),
|
||||
%% Note: we don't add `topic_mapping' again here to the parameters.
|
||||
{ok, {{_, 200, _}, _, _}} = emqx_bridge_v2_testlib:update_bridge_api(
|
||||
Config,
|
||||
#{<<"parameters">> => #{<<"topic">> => <<"new_topic">>}}
|
||||
),
|
||||
?assertMatch(
|
||||
{ok, {{_, 200, _}, _, #{<<"parameters">> := #{<<"topic">> := <<"new_topic">>}}}},
|
||||
emqx_bridge_v2_testlib:get_source_api(?SOURCE_TYPE_BIN, Name)
|
||||
),
|
||||
ok.
|
||||
|
|
Loading…
Reference in New Issue