Merge pull request #11844 from zmstone/1030-downgrade-bridge-type-for-old-api

1030 downgrade bridge type for old api
This commit is contained in:
Zaiming (Stone) Shi 2023-10-30 19:47:24 +01:00 committed by GitHub
commit c07cf9051e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 67 additions and 25 deletions

View File

@ -69,7 +69,7 @@ mix-deps-get: $(ELIXIR_COMMON_DEPS)
.PHONY: eunit .PHONY: eunit
eunit: $(REBAR) merge-config eunit: $(REBAR) merge-config
@$(REBAR) eunit --name eunit@127.0.0.1 -v -c --cover_export_name $(CT_COVER_EXPORT_PREFIX)-eunit @$(REBAR) eunit --name eunit@127.0.0.1 -c -v --cover_export_name $(CT_COVER_EXPORT_PREFIX)-eunit
.PHONY: proper .PHONY: proper
proper: $(REBAR) proper: $(REBAR)
@ -105,16 +105,22 @@ ifneq ($(GROUPS),)
GROUPS_ARG := --groups $(GROUPS) GROUPS_ARG := --groups $(GROUPS)
endif endif
ifeq ($(ENABLE_COVER_COMPILE),1)
cover_args = --cover --cover_export_name $(CT_COVER_EXPORT_PREFIX)-$(subst /,-,$1)
else
cover_args =
endif
## example: ## example:
## env SUITES=apps/appname/test/test_SUITE.erl CASES=t_foo make apps/appname-ct ## env SUITES=apps/appname/test/test_SUITE.erl CASES=t_foo make apps/appname-ct
define gen-app-ct-target define gen-app-ct-target
$1-ct: $(REBAR) merge-config clean-test-cluster-config $1-ct: $(REBAR) merge-config clean-test-cluster-config
$(eval SUITES := $(shell $(SCRIPTS)/find-suites.sh $1)) $(eval SUITES := $(shell $(SCRIPTS)/find-suites.sh $1))
ifneq ($(SUITES),) ifneq ($(SUITES),)
@$(REBAR) ct -c -v \ $(REBAR) ct -v \
--readable=$(CT_READABLE) \ --readable=$(CT_READABLE) \
--name $(CT_NODE_NAME) \ --name $(CT_NODE_NAME) \
--cover_export_name $(CT_COVER_EXPORT_PREFIX)-$(subst /,-,$1) \ $(call cover_args,$1) \
--suite $(SUITES) \ --suite $(SUITES) \
$(GROUPS_ARG) \ $(GROUPS_ARG) \
$(CASES_ARG) $(CASES_ARG)

View File

@ -902,7 +902,7 @@ format_resource(
redact( redact(
maps:merge( maps:merge(
RawConfFull#{ RawConfFull#{
type => Type, type => downgrade_type(Type),
name => maps:get(<<"name">>, RawConf, BridgeName), name => maps:get(<<"name">>, RawConf, BridgeName),
node => Node node => Node
}, },
@ -1156,3 +1156,6 @@ non_compat_bridge_msg() ->
upgrade_type(Type) -> upgrade_type(Type) ->
emqx_bridge_lib:upgrade_type(Type). emqx_bridge_lib:upgrade_type(Type).
downgrade_type(Type) ->
emqx_bridge_lib:downgrade_type(Type).

View File

@ -258,6 +258,18 @@ pre_create_atoms() ->
kafka__probe_ kafka__probe_
]. ].
http_get_bridges(UrlPath, Name0) ->
Name = iolist_to_binary(Name0),
{ok, _Code, BridgesData} = http_get(UrlPath),
Bridges = json(BridgesData),
lists:filter(
fun
(#{<<"name">> := N}) when N =:= Name -> true;
(_) -> false
end,
Bridges
).
kafka_bridge_rest_api_helper(Config) -> kafka_bridge_rest_api_helper(Config) ->
BridgeType = ?BRIDGE_TYPE, BridgeType = ?BRIDGE_TYPE,
BridgeName = "my_kafka_bridge", BridgeName = "my_kafka_bridge",
@ -277,27 +289,16 @@ kafka_bridge_rest_api_helper(Config) ->
BridgesPartsOpRestart = OpUrlFun("restart"), BridgesPartsOpRestart = OpUrlFun("restart"),
BridgesPartsOpStop = OpUrlFun("stop"), BridgesPartsOpStop = OpUrlFun("stop"),
%% List bridges %% List bridges
MyKafkaBridgeExists = fun() ->
{ok, _Code, BridgesData} = http_get(BridgesParts),
Bridges = json(BridgesData),
lists:any(
fun
(#{<<"name">> := <<"my_kafka_bridge">>}) -> true;
(_) -> false
end,
Bridges
)
end,
%% Delete if my_kafka_bridge exists %% Delete if my_kafka_bridge exists
case MyKafkaBridgeExists() of case http_get_bridges(BridgesParts, BridgeName) of
true -> [_] ->
%% Delete the bridge my_kafka_bridge %% Delete the bridge my_kafka_bridge
{ok, 204, <<>>} = http_delete(BridgesPartsIdDeleteAlsoActions); {ok, 204, <<>>} = http_delete(BridgesPartsIdDeleteAlsoActions);
false -> [] ->
ok ok
end, end,
try try
false = MyKafkaBridgeExists(), ?assertEqual([], http_get_bridges(BridgesParts, BridgeName)),
%% Create new Kafka bridge %% Create new Kafka bridge
KafkaTopic = test_topic_one_partition(), KafkaTopic = test_topic_one_partition(),
CreateBodyTmp = #{ CreateBodyTmp = #{
@ -319,7 +320,7 @@ kafka_bridge_rest_api_helper(Config) ->
CreateBody = CreateBodyTmp#{<<"ssl">> => maps:get(<<"ssl">>, Config)}, CreateBody = CreateBodyTmp#{<<"ssl">> => maps:get(<<"ssl">>, Config)},
{ok, 201, _Data} = http_post(BridgesParts, CreateBody), {ok, 201, _Data} = http_post(BridgesParts, CreateBody),
%% Check that the new bridge is in the list of bridges %% Check that the new bridge is in the list of bridges
true = MyKafkaBridgeExists(), ?assertMatch([#{<<"type">> := <<"kafka">>}], http_get_bridges(BridgesParts, BridgeName)),
%% Probe should work %% Probe should work
%% no extra atoms should be created when probing %% no extra atoms should be created when probing
%% See pre_create_atoms() above %% See pre_create_atoms() above
@ -419,8 +420,9 @@ kafka_bridge_rest_api_helper(Config) ->
% this delete should not be necessary beause of the also_delete_dep_actions flag % this delete should not be necessary beause of the also_delete_dep_actions flag
% {ok, 204, _} = http_delete(["rules", RuleId]), % {ok, 204, _} = http_delete(["rules", RuleId]),
{ok, 204, _} = http_delete(BridgesPartsIdDeleteAlsoActions), {ok, 204, _} = http_delete(BridgesPartsIdDeleteAlsoActions),
false = MyKafkaBridgeExists(), Remain = http_get_bridges(BridgesParts, BridgeName),
delete_all_bridges() delete_all_bridges(),
?assertEqual([], Remain)
end, end,
ok. ok.

View File

@ -12,15 +12,46 @@ set -euo pipefail
# ensure dir # ensure dir
cd -P -- "$(dirname -- "$0")/.." cd -P -- "$(dirname -- "$0")/.."
DIR="$1"
complete_path() {
local filename="$1"
# Check if path prefix is present
if [[ "$filename" != */* ]]; then
filename="$DIR/test/$filename"
fi
# Check if suffix is present
if [[ "$filename" != *.erl ]]; then
filename="$filename.erl"
fi
echo "$filename"
}
## EMQX_CT_SUITES or SUITES is useful in ad-hoc runs ## EMQX_CT_SUITES or SUITES is useful in ad-hoc runs
EMQX_CT_SUITES="${EMQX_CT_SUITES:-${SUITES:-}}" EMQX_CT_SUITES="${EMQX_CT_SUITES:-${SUITES:-}}"
if [ -n "${EMQX_CT_SUITES:-}" ]; then if [ -n "${EMQX_CT_SUITES:-}" ]; then
echo "${EMQX_CT_SUITES}" OUTPUT=""
IFS=',' read -ra FILE_ARRAY <<< "$EMQX_CT_SUITES"
for file in "${FILE_ARRAY[@]}"; do
path=$(complete_path "$file")
if [ ! -f "$path" ]; then
echo ''
echo "ERROR: '$path' is not a file. Ignored!" >&2
exit 1
fi
if [ -z "$OUTPUT" ]; then
OUTPUT="$path"
else
OUTPUT="$OUTPUT,$path"
fi
done
echo "${OUTPUT}"
exit 0 exit 0
fi fi
TESTDIR="$1/test" TESTDIR="$DIR/test"
INTEGRATION_TESTDIR="$1/integration_test" INTEGRATION_TESTDIR="$DIR/integration_test"
# Get the output of the find command # Get the output of the find command
IFS=$'\n' read -r -d '' -a FILES < <(find "${TESTDIR}" -name "*_SUITE.erl" 2>/dev/null | sort && printf '\0') IFS=$'\n' read -r -d '' -a FILES < <(find "${TESTDIR}" -name "*_SUITE.erl" 2>/dev/null | sort && printf '\0')
if [[ -d "${INTEGRATION_TESTDIR}" ]]; then if [[ -d "${INTEGRATION_TESTDIR}" ]]; then