summaryrefslogtreecommitdiff
path: root/chef-config
diff options
context:
space:
mode:
authorBryan McLellan <btm@chef.io>2019-04-24 14:23:07 -0400
committerBryan McLellan <btm@loftninjas.org>2019-05-06 12:56:55 -0400
commit00464d7cc3e818ee687cae1db8c087ee95187579 (patch)
treee75dc5c528d3ae96ff4bf1531f848c319688b3b7 /chef-config
parent9d5f5c40362d1fd7b0323cf0880300d6165b3a94 (diff)
downloadchef-00464d7cc3e818ee687cae1db8c087ee95187579.tar.gz
Unit tests for experimental target mode
Signed-off-by: Bryan McLellan <btm@chef.io>
Diffstat (limited to 'chef-config')
-rw-r--r--chef-config/spec/unit/config_spec.rb64
1 files changed, 60 insertions, 4 deletions
diff --git a/chef-config/spec/unit/config_spec.rb b/chef-config/spec/unit/config_spec.rb
index 0e17753185..378cc4a4a1 100644
--- a/chef-config/spec/unit/config_spec.rb
+++ b/chef-config/spec/unit/config_spec.rb
@@ -248,9 +248,10 @@ RSpec.describe ChefConfig::Config do
end
describe "default values" do
+ let(:system_drive) { ChefConfig::Config.env["SYSTEMDRIVE"] } if is_windows
let :primary_cache_path do
if is_windows
- "#{ChefConfig::Config.env['SYSTEMDRIVE']}\\chef"
+ "#{system_drive}\\chef"
else
"/var/chef"
end
@@ -275,6 +276,35 @@ RSpec.describe ChefConfig::Config do
allow(ChefConfig::Config).to receive(:path_accessible?).and_return(false)
end
+ describe "ChefConfig::Config[:client_key]" do
+ let(:path_to_client_key) { to_platform("/etc/chef") + ChefConfig::PathHelper.path_separator }
+
+ it "sets the default path to the client key" do
+ expect(ChefConfig::Config.client_key).to eq(path_to_client_key + "client.pem")
+ end
+
+ context "when target mode is enabled" do
+ let(:target_mode_host) { "fluffy.kittens.org" }
+
+ before do
+ ChefConfig::Config.target_mode.enabled = true
+ ChefConfig::Config.target_mode.host = target_mode_host
+ end
+
+ it "sets the default path to the client key with the target host name" do
+ expect(ChefConfig::Config.client_key).to eq(path_to_client_key + target_mode_host + ChefConfig::PathHelper.path_separator + "client.pem")
+ end
+ end
+
+ context "when local mode is enabled" do
+ before { ChefConfig::Config[:local_mode] = true }
+
+ it "returns nil" do
+ expect(ChefConfig::Config.client_key).to be_nil
+ end
+ end
+ end
+
describe "ChefConfig::Config[:fips]" do
let(:fips_enabled) { false }
@@ -370,16 +400,32 @@ RSpec.describe ChefConfig::Config do
end
describe "ChefConfig::Config[:cache_path]" do
+ let(:target_mode_host) { "fluffy.kittens.org" }
+ let(:target_mode_primary_cache_path) { "#{primary_cache_path}/#{target_mode_host}" }
+ let(:target_mode_secondary_cache_path) { "#{secondary_cache_path}/#{target_mode_host}" }
+
before do
if is_windows
- allow(File).to receive(:expand_path).and_return("#{ChefConfig::Config.env["SYSTEMDRIVE"]}/Path/To/Executable")
+ allow(File).to receive(:expand_path).and_return("#{system_drive}/Path/To/Executable")
end
end
+
context "when /var/chef exists and is accessible" do
- it "defaults to /var/chef" do
+ before do
allow(ChefConfig::Config).to receive(:path_accessible?).with(to_platform("/var/chef")).and_return(true)
+ end
+
+ it "defaults to /var/chef" do
expect(ChefConfig::Config[:cache_path]).to eq(primary_cache_path)
end
+
+ context "and target mode is enabled" do
+ it "cache path includes the target host name" do
+ ChefConfig::Config.target_mode.enabled = true
+ ChefConfig::Config.target_mode.host = target_mode_host
+ expect(ChefConfig::Config[:cache_path]).to eq(target_mode_primary_cache_path)
+ end
+ end
end
context "when /var/chef does not exist and /var is accessible" do
@@ -399,13 +445,23 @@ RSpec.describe ChefConfig::Config do
end
context "when /var/chef exists and is not accessible" do
- it "defaults to $HOME/.chef" do
+ before do
allow(File).to receive(:exists?).with(to_platform("/var/chef")).and_return(true)
allow(File).to receive(:readable?).with(to_platform("/var/chef")).and_return(true)
allow(File).to receive(:writable?).with(to_platform("/var/chef")).and_return(false)
+ end
+ it "defaults to $HOME/.chef" do
expect(ChefConfig::Config[:cache_path]).to eq(secondary_cache_path)
end
+
+ context "and target mode is enabled" do
+ it "cache path defaults to $HOME/.chef with the target host name" do
+ ChefConfig::Config.target_mode.enabled = true
+ ChefConfig::Config.target_mode.host = target_mode_host
+ expect(ChefConfig::Config[:cache_path]).to eq(target_mode_secondary_cache_path)
+ end
+ end
end
context "when chef is running in local mode" do