|
| 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