summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorMarc A. Paradise <marc.paradise@gmail.com>2019-04-08 12:23:10 -0400
committerMarc A. Paradise <marc.paradise@gmail.com>2019-04-24 13:25:58 -0400
commit5aa8f462bbfc3667e501866a8319087d57741f4a (patch)
tree3780200e6f6f113a8d00f53b4c5932ecea680b37 /spec
parent44c3e411344a0c9139d01ef942f92f7d42a62a89 (diff)
downloadchef-5aa8f462bbfc3667e501866a8319087d57741f4a.tar.gz
deprecate old version of changed CLI flags.
This adds a lightweight deprecation mechanism in order to warn the human that they're using deprecated flags, and to continue to allow Bootstrap to work even if that happens. Signed-off-by: Marc A. Paradise <marc.paradise@gmail.com>
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/knife/bootstrap_spec.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/spec/unit/knife/bootstrap_spec.rb b/spec/unit/knife/bootstrap_spec.rb
index 5be0999e37..e9023ff4a4 100644
--- a/spec/unit/knife/bootstrap_spec.rb
+++ b/spec/unit/knife/bootstrap_spec.rb
@@ -1564,6 +1564,7 @@ describe Chef::Knife::Bootstrap do
end
it "performs the steps we expect to run a bootstrap" do
+ expect(knife).to receive(:warn_and_map_deprecated_flags).ordered
expect(knife).to receive(:validate_name_args!).ordered
expect(knife).to receive(:validate_protocol!).ordered
expect(knife).to receive(:validate_first_boot_attributes!).ordered
@@ -1585,6 +1586,38 @@ describe Chef::Knife::Bootstrap do
end
end
+ describe "#warn_and_map_deprecated_flags" do
+ before do
+ Chef::Config[:silence_deprecation_warnings] = false
+ end
+
+
+ context "when a deprecated CLI flag is given on the CLI" do
+ before do
+ knife.config[:ssh_user] = "sshuser"
+ knife.merge_configs
+ end
+ it "maps the key value to the new key and points the human to the new flag" do
+ expect(knife.ui).to receive(:warn).with(/--ssh-user USER is deprecated. Use --connection-user USERNAME instead./)
+ knife.warn_and_map_deprecated_flags
+ expect(knife.config[:connection_user]).to eq "sshuser"
+ end
+ end
+
+ context "when a deprecated CLI flag is given on the CLI, along with its replacement" do
+ before do
+ knife.config[:ssh_user] = "sshuser"
+ knife.config[:connection_user] = "real-user"
+ knife.merge_configs
+ end
+ it "warns that both are provided and takes the non-deprecated value" do
+ expect(knife.ui).to receive(:warn).with(/You provided both --connection-user and --ssh-user.*'--connection-user real-user'/m)
+ knife.warn_and_map_deprecated_flags
+ expect(knife.config[:connection_user]).to eq "real-user"
+ end
+ end
+ end
+
describe "#register_client" do
let(:vault_handler_mock) { double("ChefVaultHandler") }
let(:client_builder_mock) { double("ClientBuilder") }