Skip to content

Commit 90878e1

Browse files
committed
Test listing of deprecated features
1 parent 661caa0 commit 90878e1

File tree

2 files changed

+196
-1
lines changed

2 files changed

+196
-1
lines changed

deps/rabbit/test/deprecated_features_SUITE.erl

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
get_appropriate_warning_when_disconnected/1,
3737
get_appropriate_warning_when_removed/1,
3838
deprecated_feature_enabled_if_feature_flag_depends_on_it/1,
39+
list_all_deprecated_features/1,
40+
list_used_deprecated_features/1,
3941

4042
feature_is_unused/1,
4143
feature_is_used/1
@@ -67,7 +69,9 @@ groups() ->
6769
get_appropriate_warning_when_denied,
6870
get_appropriate_warning_when_disconnected,
6971
get_appropriate_warning_when_removed,
70-
deprecated_feature_enabled_if_feature_flag_depends_on_it
72+
deprecated_feature_enabled_if_feature_flag_depends_on_it,
73+
list_all_deprecated_features,
74+
list_used_deprecated_features
7175
],
7276
[
7377
{cluster_size_1, [], Tests},
@@ -726,3 +730,50 @@ deprecated_feature_enabled_if_feature_flag_depends_on_it(Config) ->
726730
ok
727731
end )
728732
|| Node <- AllNodes].
733+
734+
list_all_deprecated_features(Config) ->
735+
[FirstNode | _] = AllNodes = ?config(nodes, Config),
736+
feature_flags_v2_SUITE:connect_nodes(AllNodes),
737+
feature_flags_v2_SUITE:override_running_nodes(AllNodes),
738+
739+
FeatureName = ?FUNCTION_NAME,
740+
FeatureFlags = #{FeatureName =>
741+
#{provided_by => rabbit,
742+
deprecation_phase => permitted_by_default}},
743+
?assertEqual(
744+
ok,
745+
feature_flags_v2_SUITE:inject_on_nodes(AllNodes, FeatureFlags)),
746+
747+
feature_flags_v2_SUITE:run_on_node(
748+
FirstNode,
749+
fun() ->
750+
Map = rabbit_deprecated_features:list(all),
751+
?assert(maps:is_key(FeatureName, Map))
752+
end).
753+
754+
list_used_deprecated_features(Config) ->
755+
[FirstNode | _] = AllNodes = ?config(nodes, Config),
756+
feature_flags_v2_SUITE:connect_nodes(AllNodes),
757+
feature_flags_v2_SUITE:override_running_nodes(AllNodes),
758+
759+
UsedFeatureName = used_deprecated_feature,
760+
UnusedFeatureName = unused_deprecated_feature,
761+
FeatureFlags = #{UsedFeatureName =>
762+
#{provided_by => rabbit,
763+
deprecation_phase => permitted_by_default,
764+
callbacks => #{is_feature_used => {?MODULE, feature_is_used}}},
765+
UnusedFeatureName =>
766+
#{provided_by => rabbit,
767+
deprecation_phase => permitted_by_default,
768+
callbacks => #{is_feature_used => {?MODULE, feature_is_unused}}}},
769+
?assertEqual(
770+
ok,
771+
feature_flags_v2_SUITE:inject_on_nodes(AllNodes, FeatureFlags)),
772+
773+
feature_flags_v2_SUITE:run_on_node(
774+
FirstNode,
775+
fun() ->
776+
Map = rabbit_deprecated_features:list(used),
777+
?assertNot(maps:is_key(UnusedFeatureName, Map)),
778+
?assert(maps:is_key(UsedFeatureName, Map))
779+
end).
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
## This Source Code Form is subject to the terms of the Mozilla Public
2+
## License, v. 2.0. If a copy of the MPL was not distributed with this
3+
## file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
##
5+
## Copyright (c) 2018-2020 VMware, Inc. or its affiliates. All rights reserved.
6+
7+
defmodule ListDeprecatedFeaturesCommandTest do
8+
use ExUnit.Case, async: false
9+
import TestHelper
10+
11+
@command RabbitMQ.CLI.Ctl.Commands.ListDeprecatedFeaturesCommand
12+
13+
@df1 :df1_from_list_df_testsuite
14+
@df2 :df2_from_list_df_testsuite
15+
16+
setup_all do
17+
RabbitMQ.CLI.Core.Distribution.start()
18+
19+
# Define an arbitrary deprecated feature for the test.
20+
node = get_rabbit_hostname()
21+
22+
new_deprecated_features = %{
23+
@df1 => %{
24+
desc: ~c"My deprecated feature #1",
25+
provided_by: :ListDeprecatedFeaturesCommandTest,
26+
deprecation_phase: :permitted_by_default
27+
},
28+
@df2 => %{
29+
desc: ~c"My deprecated feature #2",
30+
provided_by: :ListDeprecatedFeaturesCommandTest,
31+
deprecation_phase: :removed
32+
}
33+
}
34+
35+
:ok =
36+
:rabbit_misc.rpc_call(
37+
node,
38+
:rabbit_feature_flags,
39+
:inject_test_feature_flags,
40+
[new_deprecated_features]
41+
)
42+
43+
name_result = [
44+
[{:name, @df1}],
45+
[{:name, @df2}]
46+
]
47+
48+
full_result = [
49+
[{:name, @df1}, {:deprecation_phase, :permitted_by_default}],
50+
[{:name, @df2}, {:deprecation_phase, :removed}]
51+
]
52+
53+
{
54+
:ok,
55+
name_result: name_result, full_result: full_result
56+
}
57+
end
58+
59+
setup context do
60+
{
61+
:ok,
62+
opts: %{node: get_rabbit_hostname(), timeout: context[:test_timeout], used: false}
63+
}
64+
end
65+
66+
test "merge_defaults with no command, print just use the names" do
67+
assert match?({["name", "deprecation_phase"], %{}}, @command.merge_defaults([], %{}))
68+
end
69+
70+
test "validate: return bad_info_key on a single bad arg", context do
71+
assert @command.validate(["quack"], context[:opts]) ==
72+
{:validation_failure, {:bad_info_key, [:quack]}}
73+
end
74+
75+
test "validate: returns multiple bad args return a list of bad info key values", context do
76+
result = @command.validate(["quack", "oink"], context[:opts])
77+
assert match?({:validation_failure, {:bad_info_key, _}}, result)
78+
{_, {_, keys}} = result
79+
assert :lists.sort(keys) == [:oink, :quack]
80+
end
81+
82+
test "validate: return bad_info_key on mix of good and bad args", context do
83+
assert @command.validate(["quack", "name"], context[:opts]) ==
84+
{:validation_failure, {:bad_info_key, [:quack]}}
85+
86+
assert @command.validate(["name", "oink"], context[:opts]) ==
87+
{:validation_failure, {:bad_info_key, [:oink]}}
88+
89+
assert @command.validate(["name", "oink", "deprecation_phase"], context[:opts]) ==
90+
{:validation_failure, {:bad_info_key, [:oink]}}
91+
end
92+
93+
test "run: on a bad RabbitMQ node, return a badrpc" do
94+
opts = %{node: :jake@thedog, timeout: 200, used: false}
95+
assert match?({:badrpc, _}, @command.run(["name"], opts))
96+
end
97+
98+
@tag test_timeout: :infinity
99+
test "run: with the name tag, print just the names", context do
100+
matches_found = @command.run(["name"], context[:opts])
101+
102+
assert Enum.all?(context[:name_result], fn feature_name ->
103+
Enum.find(matches_found, fn found -> found == feature_name end)
104+
end)
105+
end
106+
107+
@tag test_timeout: :infinity
108+
test "run: with the name tag, print just the names for used features", context do
109+
opts = %{node: get_rabbit_hostname(), timeout: context[:test_timeout], used: true}
110+
matches_found = @command.run(["name"], opts)
111+
112+
assert Enum.empty?(matches_found)
113+
end
114+
115+
@tag test_timeout: :infinity
116+
test "run: duplicate args do not produce duplicate entries", context do
117+
# checks to ensure that all expected deprecated features are in the results
118+
matches_found = @command.run(["name", "name"], context[:opts])
119+
120+
assert Enum.all?(context[:name_result], fn feature_name ->
121+
Enum.find(matches_found, fn found -> found == feature_name end)
122+
end)
123+
end
124+
125+
@tag test_timeout: 30000
126+
test "run: sufficiently long timeouts don't interfere with results", context do
127+
matches_found = @command.run(["name", "deprecation_phase"], context[:opts])
128+
129+
assert Enum.all?(context[:full_result], fn feature_name ->
130+
Enum.find(matches_found, fn found -> found == feature_name end)
131+
end)
132+
end
133+
134+
@tag test_timeout: 0, username: "guest"
135+
test "run: timeout causes command to return a bad RPC", context do
136+
assert @command.run(["name", "state"], context[:opts]) ==
137+
{:badrpc, :timeout}
138+
end
139+
140+
@tag test_timeout: :infinity
141+
test "banner", context do
142+
assert @command.banner([], context[:opts]) =~ ~r/Listing deprecated features \.\.\./
143+
end
144+
end

0 commit comments

Comments
 (0)