summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorBryan McLellan <btm@loftninjas.org>2019-05-06 12:42:28 -0400
committerGitHub <noreply@github.com>2019-05-06 12:42:28 -0400
commit4e9dddc3a7667c22a5f76217f2ea6195574cccba (patch)
treef090f616249128cf3a325c8d79b646a1775118c6 /spec
parent3f8efb05853364bcff846e9f98bb6fbf6773fe58 (diff)
parenta1c438aa2b15b310ecccd062ae714026f39d3f12 (diff)
downloadchef-4e9dddc3a7667c22a5f76217f2ea6195574cccba.tar.gz
Merge pull request #8442 from chef/mp/bootstrap/restore-prerelease
Restore bootstrap pre-release support
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/knife/bootstrap_spec.rb22
-rw-r--r--spec/unit/knife/core/bootstrap_context_spec.rb43
-rw-r--r--spec/unit/knife/core/windows_bootstrap_context_spec.rb25
-rw-r--r--spec/unit/knife_spec.rb21
4 files changed, 54 insertions, 57 deletions
diff --git a/spec/unit/knife/bootstrap_spec.rb b/spec/unit/knife/bootstrap_spec.rb
index 995a2ef4c9..4261a3a166 100644
--- a/spec/unit/knife/bootstrap_spec.rb
+++ b/spec/unit/knife/bootstrap_spec.rb
@@ -1603,29 +1603,31 @@ describe Chef::Knife::Bootstrap do
end
context "when a deprecated CLI flag is given on the CLI" do
- before do
- knife.config[:ssh_user] = "sshuser"
- knife.merge_configs
- end
+ 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(/--ssh-user USER is deprecated. Use --connection-user USERNAME instead./)
+ 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"
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
+ let(:bootstrap_cli_options) { %w{--connection-user a --ssh-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 and --ssh-user.*Please use.*/m)
expect { knife.verify_deprecated_flags! }.to raise_error SystemExit
end
end
+
+ context "when a deprecated boolean CLI flag is given on the CLI, and its non-boolean replacement is used" do
+ let(:bootstrap_cli_options) { %w{--prerelease} }
+ it "correctly maps the old boolean value to the new value" do
+ expect(knife.ui).to receive(:warn)
+ knife.verify_deprecated_flags!
+ expect(knife.config[:channel]).to eq "current"
+ end
+ end
end
describe "#register_client" do
diff --git a/spec/unit/knife/core/bootstrap_context_spec.rb b/spec/unit/knife/core/bootstrap_context_spec.rb
index 2ed8b6bc51..d57e254793 100644
--- a/spec/unit/knife/core/bootstrap_context_spec.rb
+++ b/spec/unit/knife/core/bootstrap_context_spec.rb
@@ -156,25 +156,6 @@ describe Chef::Knife::Core::BootstrapContext do
end
end
- describe "when a bootstrap_version is specified" do
- let(:chef_config) do
- {
- knife: { bootstrap_version: "11.12.4" },
- }
- end
-
- it "should send the full version to the installer" do
- expect(bootstrap_context.latest_current_chef_version_string).to eq("-v 11.12.4")
- end
- end
-
- describe "when a bootstrap_version is not specified" do
- it "should send the latest current to the installer" do
- # Intentionally hard coded in order not to replicate the logic.
- expect(bootstrap_context.latest_current_chef_version_string).to eq("-v #{Chef::VERSION.to_i}")
- end
- end
-
describe "ssl_verify_mode" do
it "isn't set in the config_content by default" do
expect(bootstrap_context.config_content).not_to include("ssl_verify_mode")
@@ -292,4 +273,28 @@ describe Chef::Knife::Core::BootstrapContext do
end
end
+
+ describe "#version_to_install" do
+ context "when bootstrap_version is provided" do
+ let(:chef_config) { { knife: { bootstrap_version: "awesome" } } }
+
+ it "returns bootstrap_version" do
+ expect(bootstrap_context.version_to_install).to eq "awesome"
+ end
+ end
+
+ context "when bootstrap_version is not provided" do
+ let(:config) { { channel: "stable" } }
+ it "returns the currently running major version out of Chef::VERSION" do
+ expect(bootstrap_context.version_to_install).to eq Chef::VERSION.split(".").first
+ end
+ end
+
+ context "and channel is other than stable" do
+ let(:config) { { channel: "unstable" } }
+ it "returns the version string 'latest'" do
+ expect(bootstrap_context.version_to_install).to eq "latest"
+ end
+ end
+ end
end
diff --git a/spec/unit/knife/core/windows_bootstrap_context_spec.rb b/spec/unit/knife/core/windows_bootstrap_context_spec.rb
index a19ad11247..7bc73c113a 100644
--- a/spec/unit/knife/core/windows_bootstrap_context_spec.rb
+++ b/spec/unit/knife/core/windows_bootstrap_context_spec.rb
@@ -176,29 +176,30 @@ describe Chef::Knife::Core::WindowsBootstrapContext do
end
end
- describe "latest_current_windows_chef_version_query" do
- it "returns the major version of the current version of Chef" do
- stub_const("Chef::VERSION", "15.1.2")
- expect(bootstrap_context.latest_current_windows_chef_version_query).to eq("&v=15")
- end
-
- end
-
describe "msi_url" do
- context "when config option is not set" do
+ context "when msi_url config option is not set" do
+ let(:config) { { channel: "stable" } }
before do
- expect(bootstrap_context).to receive(:latest_current_windows_chef_version_query).and_return("&v=something")
+ expect(bootstrap_context).to receive(:version_to_install).and_return("something")
end
it "returns a chef.io msi url with minimal url parameters" do
- reference_url = "https://www.chef.io/chef/download?p=windows&v=something"
+ reference_url = "https://www.chef.io/chef/download?p=windows&channel=stable&v=something"
expect(bootstrap_context.msi_url).to eq(reference_url)
end
it "returns a chef.io msi url with provided url parameters substituted" do
- reference_url = "https://www.chef.io/chef/download?p=windows&pv=machine&m=arch&DownloadContext=ctx&v=something"
+ reference_url = "https://www.chef.io/chef/download?p=windows&pv=machine&m=arch&DownloadContext=ctx&channel=stable&v=something"
expect(bootstrap_context.msi_url("machine", "arch", "ctx")).to eq(reference_url)
end
+
+ context "when a channel is provided in config" do
+ let(:config) { { channel: "current" } }
+ it "returns a chef.io msi url with the requested channel" do
+ reference_url = "https://www.chef.io/chef/download?p=windows&channel=current&v=something"
+ expect(bootstrap_context.msi_url).to eq(reference_url)
+ end
+ end
end
context "when msi_url config option is set" do
diff --git a/spec/unit/knife_spec.rb b/spec/unit/knife_spec.rb
index 7e05bec8f7..6fcb831531 100644
--- a/spec/unit/knife_spec.rb
+++ b/spec/unit/knife_spec.rb
@@ -299,37 +299,26 @@ describe Chef::Knife do
expect(Chef::Config[:log_level]).to eql(:warn)
end
- it "prefers the default value if no config or command line value is present and reports the source as default" do
+ it "prefers the default value from option definition if no config or command line value is present and reports the source as default" do
knife_command = KnifeSpecs::TestYourself.new([]) # empty argv
knife_command.configure_chef
expect(knife_command.config[:opt_with_default]).to eq("default-value")
+ expect(knife_command.config_source(:opt_with_default)).to eq(:cli_default)
end
- it "prefers a value in Chef::Config[:knife] to the default" do
+ it "prefers a value in Chef::Config[:knife] to the default and reports the source as config" do
Chef::Config[:knife][:opt_with_default] = "from-knife-config"
knife_command = KnifeSpecs::TestYourself.new([]) # empty argv
knife_command.configure_chef
expect(knife_command.config[:opt_with_default]).to eq("from-knife-config")
- expect(knife_command.config_source(:opt_with_default)).to eq (:config)
- end
-
- it "correctly reports Chef::Config as the source when a a config entry comes from there" do
- Chef::Config[:knife][:opt_with_default] = "from-knife-config"
- knife_command = KnifeSpecs::TestYourself.new([]) # empty argv
- knife_command.configure_chef
- expect(knife_command.config_source(:opt_with_default)).to eq (:config)
+ expect(knife_command.config_source(:opt_with_default)).to eq(:config)
end
it "prefers a value from command line over Chef::Config and the default and reports the source as CLI" do
knife_command = KnifeSpecs::TestYourself.new(["-D", "from-cli"])
knife_command.configure_chef
expect(knife_command.config[:opt_with_default]).to eq("from-cli")
- expect(knife_command.config_source(:opt_with_default)).to eq (:cli)
- end
- it "correctly reports CLI as the source when a config entry comes from the CLI" do
- knife_command = KnifeSpecs::TestYourself.new(["-D", "from-cli"])
- knife_command.configure_chef
- expect(knife_command.config_source(:opt_with_default)).to eq (:cli)
+ expect(knife_command.config_source(:opt_with_default)).to eq(:cli)
end
it "merges `listen` config to Chef::Config" do