summaryrefslogtreecommitdiff
path: root/spec/unit/knife/core/bootstrap_context_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit/knife/core/bootstrap_context_spec.rb')
-rw-r--r--spec/unit/knife/core/bootstrap_context_spec.rb59
1 files changed, 37 insertions, 22 deletions
diff --git a/spec/unit/knife/core/bootstrap_context_spec.rb b/spec/unit/knife/core/bootstrap_context_spec.rb
index 6f7adfcf57..3718cb228c 100644
--- a/spec/unit/knife/core/bootstrap_context_spec.rb
+++ b/spec/unit/knife/core/bootstrap_context_spec.rb
@@ -39,18 +39,18 @@ describe Chef::Knife::Core::BootstrapContext do
end
it "runs chef with the first-boot.json in the _default environment" do
- bootstrap_context.start_chef.should eq "chef-client -j /etc/chef/first-boot.json -E _default"
+ expect(bootstrap_context.start_chef).to eq "chef-client -j /etc/chef/first-boot.json -E _default"
end
describe "when in verbosity mode" do
let(:config) { {:verbosity => 2} }
it "adds '-l debug' when verbosity is >= 2" do
- bootstrap_context.start_chef.should eq "chef-client -j /etc/chef/first-boot.json -l debug -E _default"
+ expect(bootstrap_context.start_chef).to eq "chef-client -j /etc/chef/first-boot.json -l debug -E _default"
end
end
it "reads the validation key" do
- bootstrap_context.validation_key.should eq IO.read(File.join(CHEF_SPEC_DATA, 'ssl', 'private_key.pem'))
+ expect(bootstrap_context.validation_key).to eq IO.read(File.join(CHEF_SPEC_DATA, 'ssl', 'private_key.pem'))
end
it "generates the config file data" do
@@ -60,7 +60,7 @@ chef_server_url "http://chef.example.com:4444"
validation_client_name "chef-validator-testing"
# Using default node name (fqdn)
EXPECTED
- bootstrap_context.config_content.should eq expected
+ expect(bootstrap_context.config_content).to eq expected
end
it "does not set a default log_level" do
@@ -70,14 +70,15 @@ EXPECTED
describe "alternate chef-client path" do
let(:chef_config){ {:chef_client_path => '/usr/local/bin/chef-client'} }
it "runs chef-client from another path when specified" do
- bootstrap_context.start_chef.should eq "/usr/local/bin/chef-client -j /etc/chef/first-boot.json -E _default"
+ expect(bootstrap_context.start_chef).to eq "/usr/local/bin/chef-client -j /etc/chef/first-boot.json -E _default"
end
end
describe "validation key path that contains a ~" do
let(:chef_config){ {:validation_key => '~/my.key'} }
it "reads the validation key when it contains a ~" do
- IO.should_receive(:read).with(File.expand_path("my.key", ENV['HOME']))
+ expect(File).to receive(:exist?).with(File.expand_path("my.key", ENV['HOME'])).and_return(true)
+ expect(IO).to receive(:read).with(File.expand_path("my.key", ENV['HOME']))
bootstrap_context.validation_key
end
end
@@ -85,44 +86,44 @@ EXPECTED
describe "when an explicit node name is given" do
let(:config){ {:chef_node_name => 'foobar.example.com' }}
it "sets the node name in the client.rb" do
- bootstrap_context.config_content.should match(/node_name "foobar\.example\.com"/)
+ expect(bootstrap_context.config_content).to match(/node_name "foobar\.example\.com"/)
end
end
describe "when bootstrapping into a specific environment" do
let(:chef_config){ {:environment => "prodtastic"} }
it "starts chef in the configured environment" do
- bootstrap_context.start_chef.should == 'chef-client -j /etc/chef/first-boot.json -E prodtastic'
+ expect(bootstrap_context.start_chef).to eq('chef-client -j /etc/chef/first-boot.json -E prodtastic')
end
end
describe "when JSON attributes are given" do
let(:config) { {:first_boot_attributes => {:baz => :quux}} }
it "adds the attributes to first_boot" do
- Chef::JSONCompat.to_json(bootstrap_context.first_boot).should eq(Chef::JSONCompat.to_json({:baz => :quux, :run_list => run_list}))
+ expect(Chef::JSONCompat.to_json(bootstrap_context.first_boot)).to eq(Chef::JSONCompat.to_json({:baz => :quux, :run_list => run_list}))
end
end
describe "when JSON attributes are NOT given" do
it "sets first_boot equal to run_list" do
- Chef::JSONCompat.to_json(bootstrap_context.first_boot).should eq(Chef::JSONCompat.to_json({:run_list => run_list}))
+ expect(Chef::JSONCompat.to_json(bootstrap_context.first_boot)).to eq(Chef::JSONCompat.to_json({:run_list => run_list}))
end
end
describe "when an encrypted_data_bag_secret is provided" do
let(:secret) { "supersekret" }
it "reads the encrypted_data_bag_secret" do
- bootstrap_context.encrypted_data_bag_secret.should eq "supersekret"
+ expect(bootstrap_context.encrypted_data_bag_secret).to eq "supersekret"
end
end
describe "to support compatibility with existing templates" do
it "sets the @config instance variable" do
- bootstrap_context.instance_variable_get(:@config).should eq config
+ expect(bootstrap_context.instance_variable_get(:@config)).to eq config
end
it "sets the @run_list instance variable" do
- bootstrap_context.instance_variable_get(:@run_list).should eq run_list
+ expect(bootstrap_context.instance_variable_get(:@run_list)).to eq run_list
end
end
@@ -134,7 +135,7 @@ EXPECTED
end
it "should send the full version to the installer" do
- bootstrap_context.latest_current_chef_version_string.should eq("-v 11.12.4")
+ expect(bootstrap_context.latest_current_chef_version_string).to eq("-v 11.12.4")
end
end
@@ -146,20 +147,20 @@ EXPECTED
end
it "should send the full version to the installer and set the pre-release flag" do
- bootstrap_context.latest_current_chef_version_string.should eq("-v 11.12.4.rc.0 -p")
+ expect(bootstrap_context.latest_current_chef_version_string).to eq("-v 11.12.4.rc.0 -p")
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.
- bootstrap_context.latest_current_chef_version_string.should eq("-v #{Chef::VERSION.to_i}")
+ 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
- bootstrap_context.config_content.should_not include("ssl_verify_mode")
+ expect(bootstrap_context.config_content).not_to include("ssl_verify_mode")
end
describe "when configured in config" do
@@ -170,14 +171,14 @@ EXPECTED
end
it "uses the config value" do
- bootstrap_context.config_content.should include("ssl_verify_mode :verify_peer")
+ expect(bootstrap_context.config_content).to include("ssl_verify_mode :verify_peer")
end
describe "when configured via CLI" do
let(:config) {{:node_ssl_verify_mode => "none"}}
it "uses CLI value" do
- bootstrap_context.config_content.should include("ssl_verify_mode :verify_none")
+ expect(bootstrap_context.config_content).to include("ssl_verify_mode :verify_none")
end
end
end
@@ -185,7 +186,7 @@ EXPECTED
describe "verify_api_cert" do
it "isn't set in the config_content by default" do
- bootstrap_context.config_content.should_not include("verify_api_cert")
+ expect(bootstrap_context.config_content).not_to include("verify_api_cert")
end
describe "when configured in config" do
@@ -196,17 +197,31 @@ EXPECTED
end
it "uses the config value" do
- bootstrap_context.config_content.should include("verify_api_cert false")
+ expect(bootstrap_context.config_content).to include("verify_api_cert false")
end
describe "when configured via CLI" do
let(:config) {{:node_verify_api_cert => true}}
it "uses CLI value" do
- bootstrap_context.config_content.should include("verify_api_cert true")
+ expect(bootstrap_context.config_content).to include("verify_api_cert true")
end
end
end
end
+ describe "prerelease" do
+ it "isn't set in the config_content by default" do
+ expect(bootstrap_context.config_content).not_to include("prerelease")
+ end
+
+ describe "when configured via cli" do
+ let(:config) {{:prerelease => true}}
+
+ it "uses CLI value" do
+ expect(bootstrap_context.latest_current_chef_version_string).to eq("-p")
+ end
+ end
+ end
+
end