summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorNimesh <36878084+Nimesh-Msys@users.noreply.github.com>2019-06-05 20:29:35 +0530
committerBryan McLellan <btm@chef.io>2019-06-05 10:59:35 -0400
commiteb27732839ede9db19abcc48e8a824d5f80806c3 (patch)
tree275ebcb8ef64e103d60af7052ef93ccbfbd52616 /spec
parenta25d9108d4d6d15f173a86b82dcbf1911d2f2810 (diff)
downloadchef-eb27732839ede9db19abcc48e8a824d5f80806c3.tar.gz
Chef-15: Adding short argument's deprecation check (#8626)
- Handles "-x" that was used to set "winrm-user" and is now Deprecated. - Using symmetrical "USERNAME" and "PASSWORD" verbiages while displaying deprecated warnings. - Added test cases - Ensured Chefstyle - Fixes MSYS-1046 Signed-off-by: Nimesh-Msys <nimesh.patni@msystechnologies.com>
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/knife/bootstrap_spec.rb90
1 files changed, 79 insertions, 11 deletions
diff --git a/spec/unit/knife/bootstrap_spec.rb b/spec/unit/knife/bootstrap_spec.rb
index f92af74284..b04269e3df 100644
--- a/spec/unit/knife/bootstrap_spec.rb
+++ b/spec/unit/knife/bootstrap_spec.rb
@@ -1,6 +1,7 @@
#
# Author:: Ian Meyer (<ianmmeyer@gmail.com>)
# Copyright:: Copyright 2010-2016, Ian Meyer
+# Copyright:: Copyright 2010-2019, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -1684,20 +1685,87 @@ describe Chef::Knife::Bootstrap do
end
context "when a deprecated CLI flag is given on the CLI" do
- let(:bootstrap_cli_options) { %w{--ssh-user sshuser} }
- 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(/You provided --ssh-user. This flag is deprecated. Please use '--connection-user USERNAME' instead./)
- knife.verify_deprecated_flags!
- expect(knife.config[:connection_user]).to eq "sshuser"
+ context "with flag containing only long argument" do
+ context "when given with no other options" do
+ let(:bootstrap_cli_options) { %w{--winrm-transport XXX} }
+ 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("You provided --winrm-transport. This flag is deprecated. Please use '--winrm-ssl' instead.")
+ knife.verify_deprecated_flags!
+ expect(knife.config[:winrm_ssl]).to eq "XXX"
+ end
+ end
+ context "when given along with valid flag" do
+ let(:bootstrap_cli_options) { %w{--winrm-transport XXX --connection-user user-a} }
+ 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("You provided --winrm-transport. This flag is deprecated. Please use '--winrm-ssl' instead.")
+ knife.verify_deprecated_flags!
+ expect(knife.config[:winrm_ssl]).to eq "XXX"
+ expect(knife.config[:connection_user]).to eq "user-a"
+ end
+ end
+ context "when given along with its replacement" do
+ let(:bootstrap_cli_options) { %w{--winrm-transport XXX --winrm-ssl YYY} }
+ it "informs the human that both are provided and exits" do
+ expect(knife.ui).to receive(:error).with(/You provided both --winrm-ssl and --winrm-transport.*Please use.*/m)
+ expect { knife.verify_deprecated_flags! }.to raise_error SystemExit
+ end
+ end
end
- end
- context "when a deprecated CLI flag is given on the CLI, along with its replacement" do
- let(:bootstrap_cli_options) { %w{--connection-user a --ssh-user b} }
+ context "with flag also contains short argument" do
+ context "when given as short arg" do
+ context "with no other options" do
+ let(:bootstrap_cli_options) { %w{-x user-a} }
+ it "maps the key value to the new key and display information with both long and short arguments" do
+ expect(knife.ui).to receive(:warn).with("You provided --winrm-user(or -x). This flag is deprecated. Please use '--connection-user USERNAME(or -U USERNAME)' instead.")
+ knife.verify_deprecated_flags!
+ expect(knife.config[:connection_user]).to eq "user-a"
+ end
+ end
+ context "along with valid flag" do
+ let(:bootstrap_cli_options) { %w{-x user-a --connection-password XXX} }
+ it "maps the key value to the new key and display information with both long and short arguments" do
+ expect(knife.ui).to receive(:warn).with("You provided --winrm-user(or -x). This flag is deprecated. Please use '--connection-user USERNAME(or -U USERNAME)' instead.")
+ knife.verify_deprecated_flags!
+ expect(knife.config[:connection_user]).to eq "user-a"
+ expect(knife.config[:connection_password]).to eq "XXX"
+ end
+ end
+ context "along with its replacement" do
+ let(:bootstrap_cli_options) { %w{-x user-a --connection-user user-b} }
+ it "informs the human that both are provided and exits" do
+ expect(knife.ui).to receive(:error).with("You provided both --connection-user(or -U) and --winrm-user(or -x).\n\nPlease use one or the other, but note that\n--winrm-user USERNAME is deprecated.\n")
+ expect { knife.verify_deprecated_flags! }.to raise_error SystemExit
+ end
+ end
+ end
- it "informs the human that both are provided and exits" do
- expect(knife.ui).to receive(:error).with(/You provided both --connection-user and --ssh-user.*Please use.*/m)
- expect { knife.verify_deprecated_flags! }.to raise_error SystemExit
+ context "when given as long arg" do
+ context "with no other options" do
+ let(:bootstrap_cli_options) { %w{--winrm-user user-a} }
+ it "maps the key value to the new key and display information with both long and short arguments" do
+ expect(knife.ui).to receive(:warn).with("You provided --winrm-user(or -x). This flag is deprecated. Please use '--connection-user USERNAME(or -U USERNAME)' instead.")
+ knife.verify_deprecated_flags!
+ expect(knife.config[:connection_user]).to eq "user-a"
+ end
+ end
+ context "along with valid flag" do
+ let(:bootstrap_cli_options) { %w{--winrm-user user-a --connection-password XXX} }
+ it "maps the key value to the new key and display information with both long and short arguments" do
+ expect(knife.ui).to receive(:warn).with("You provided --winrm-user(or -x). This flag is deprecated. Please use '--connection-user USERNAME(or -U USERNAME)' instead.")
+ knife.verify_deprecated_flags!
+ expect(knife.config[:connection_user]).to eq "user-a"
+ expect(knife.config[:connection_password]).to eq "XXX"
+ end
+ end
+ context "along with its replacement" do
+ let(:bootstrap_cli_options) { %w{--winrm-user user-a --connection-user user-b} }
+ it "informs the human that both are provided and exits" do
+ expect(knife.ui).to receive(:error).with("You provided both --connection-user(or -U) and --winrm-user(or -x).\n\nPlease use one or the other, but note that\n--winrm-user USERNAME is deprecated.\n")
+ expect { knife.verify_deprecated_flags! }.to raise_error SystemExit
+ end
+ end
+ end
end
end