diff --git a/apps/emqx_bridge/test/emqx_bridge_v2_testlib.erl b/apps/emqx_bridge/test/emqx_bridge_v2_testlib.erl index 9def284d9..6729a16e7 100644 --- a/apps/emqx_bridge/test/emqx_bridge_v2_testlib.erl +++ b/apps/emqx_bridge/test/emqx_bridge_v2_testlib.erl @@ -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) -> diff --git a/apps/emqx_bridge_gcp_pubsub/test/emqx_bridge_gcp_pubsub_consumer_SUITE.erl b/apps/emqx_bridge_gcp_pubsub/test/emqx_bridge_gcp_pubsub_consumer_SUITE.erl index ac6ec04ab..c96eeeccf 100644 --- a/apps/emqx_bridge_gcp_pubsub/test/emqx_bridge_gcp_pubsub_consumer_SUITE.erl +++ b/apps/emqx_bridge_gcp_pubsub/test/emqx_bridge_gcp_pubsub_consumer_SUITE.erl @@ -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), diff --git a/apps/emqx_bridge_gcp_pubsub/test/emqx_bridge_v2_gcp_pubsub_consumer_SUITE.erl b/apps/emqx_bridge_gcp_pubsub/test/emqx_bridge_v2_gcp_pubsub_consumer_SUITE.erl index 34ee4599e..0a9e23704 100644 --- a/apps/emqx_bridge_gcp_pubsub/test/emqx_bridge_v2_gcp_pubsub_consumer_SUITE.erl +++ b/apps/emqx_bridge_gcp_pubsub/test/emqx_bridge_v2_gcp_pubsub_consumer_SUITE.erl @@ -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.