summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorClaire McQuin <claire@getchef.com>2014-05-19 13:55:18 -0700
committerClaire McQuin <claire@getchef.com>2014-05-22 12:16:36 -0700
commit7d2891419ef04288ddd7bb2322df41cc9bd203dd (patch)
tree354eb64b83b99b4803fb8f7850483e9aca945f20 /spec
parent92519eb2cf7ae1b362f22d5710a229c5809a47cc (diff)
downloadchef-7d2891419ef04288ddd7bb2322df41cc9bd203dd.tar.gz
Put cache at HOME/.chef.d if /var/chef can't be accessed.
Diffstat (limited to 'spec')
-rw-r--r--spec/integration/knife/chef_repo_path_spec.rb1
-rw-r--r--spec/integration/knife/deps_spec.rb4
-rw-r--r--spec/integration/knife/list_spec.rb4
-rw-r--r--spec/integration/knife/raw_spec.rb4
-rw-r--r--spec/integration/knife/redirection_spec.rb4
-rw-r--r--spec/integration/knife/show_spec.rb4
-rw-r--r--spec/unit/client_spec.rb1
-rw-r--r--spec/unit/config_spec.rb75
-rw-r--r--spec/unit/role_spec.rb6
-rw-r--r--spec/unit/run_lock_spec.rb2
10 files changed, 94 insertions, 11 deletions
diff --git a/spec/integration/knife/chef_repo_path_spec.rb b/spec/integration/knife/chef_repo_path_spec.rb
index 87619d8a58..154a8d9718 100644
--- a/spec/integration/knife/chef_repo_path_spec.rb
+++ b/spec/integration/knife/chef_repo_path_spec.rb
@@ -806,6 +806,7 @@ EOM
Chef::Config.delete("#{object_name}_path".to_sym)
end
Chef::Config.delete(:chef_repo_path)
+ Chef::Config[:cache_path] = windows? ? 'C:\chef' : '/var/chef'
Chef::Config.data_bag_path = File.join(@repository_dir, 'data_bags')
end
diff --git a/spec/integration/knife/deps_spec.rb b/spec/integration/knife/deps_spec.rb
index 5ede0caef3..56820bc2b3 100644
--- a/spec/integration/knife/deps_spec.rb
+++ b/spec/integration/knife/deps_spec.rb
@@ -340,6 +340,10 @@ EOM
end
context 'remote' do
+ before do
+ Chef::Config[:cache_path] = windows? ? 'C:\chef' : '/var/chef'
+ end
+
when_the_chef_server 'has a role with no run_list' do
role 'starring', {}
it 'knife deps reports no dependencies' do
diff --git a/spec/integration/knife/list_spec.rb b/spec/integration/knife/list_spec.rb
index b9d75ce1f1..37e6f7fdb2 100644
--- a/spec/integration/knife/list_spec.rb
+++ b/spec/integration/knife/list_spec.rb
@@ -22,6 +22,10 @@ describe 'knife list' do
extend IntegrationSupport
include KnifeSupport
+ before do
+ Chef::Config[:cache_path] = windows? ? 'C:\chef' : '/var/chef'
+ end
+
when_the_chef_server "is empty" do
it "knife list / returns all top level directories" do
knife('list /').should_succeed <<EOM
diff --git a/spec/integration/knife/raw_spec.rb b/spec/integration/knife/raw_spec.rb
index fafd0a47ee..5cada50cc5 100644
--- a/spec/integration/knife/raw_spec.rb
+++ b/spec/integration/knife/raw_spec.rb
@@ -24,6 +24,10 @@ describe 'knife raw' do
include KnifeSupport
include AppServerSupport
+ before do
+ Chef::Config[:cache_path] = windows? ? 'C:\chef' : '/var/chef'
+ end
+
when_the_chef_server "has one of each thing" do
client 'x', '{}'
cookbook 'x', '1.0.0', { 'metadata.rb' => 'version "1.0.0"' }
diff --git a/spec/integration/knife/redirection_spec.rb b/spec/integration/knife/redirection_spec.rb
index 2ed49a7b24..481c57eebd 100644
--- a/spec/integration/knife/redirection_spec.rb
+++ b/spec/integration/knife/redirection_spec.rb
@@ -23,6 +23,10 @@ describe 'redirection' do
include KnifeSupport
include AppServerSupport
+ before do
+ Chef::Config[:cache_path] = windows? ? 'C:\chef' : '/var/chef'
+ end
+
when_the_chef_server 'has a role' do
role 'x', {}
diff --git a/spec/integration/knife/show_spec.rb b/spec/integration/knife/show_spec.rb
index a061fab040..3755c84b9f 100644
--- a/spec/integration/knife/show_spec.rb
+++ b/spec/integration/knife/show_spec.rb
@@ -22,6 +22,10 @@ describe 'knife show' do
extend IntegrationSupport
include KnifeSupport
+ before do
+ Chef::Config[:cache_path] = windows? ? 'C:\chef' : '/var/chef'
+ end
+
when_the_chef_server "has one of each thing" do
client 'x', '{}'
cookbook 'x', '1.0.0', { 'metadata.rb' => 'version "1.0.0"' }
diff --git a/spec/unit/client_spec.rb b/spec/unit/client_spec.rb
index 36a0e9fc1b..37a2dc09ca 100644
--- a/spec/unit/client_spec.rb
+++ b/spec/unit/client_spec.rb
@@ -272,6 +272,7 @@ describe Chef::Client do
before do
Chef::Config[:client_fork] = enable_fork
+ Chef::Config[:cache_path] = windows? ? 'C:\chef' : '/var/chef'
stub_const("Chef::Client::STDOUT_FD", stdout)
stub_const("Chef::Client::STDERR_FD", stderr)
diff --git a/spec/unit/config_spec.rb b/spec/unit/config_spec.rb
index 82506f556c..d1449e221e 100644
--- a/spec/unit/config_spec.rb
+++ b/spec/unit/config_spec.rb
@@ -138,13 +138,70 @@ describe Chef::Config do
end
describe "default values" do
+ def primary_cache_path
+ if windows?
+ "#{Chef::Config.env['SYSTEMDRIVE']}\\chef"
+ else
+ "/var/chef"
+ end
+ end
- it "Chef::Config[:file_backup_path] defaults to /var/chef/backup" do
- backup_path = if windows?
- "#{ENV['SYSTEMDRIVE']}\\chef\\backup"
+ def secondary_cache_path
+ if windows?
+ "#{Chef::Config.env['SYSTEMDRIVE']}\\#{Chef::Config.env['HOMEPATH']}\\.chef.d"
else
- "/var/chef/backup"
+ "#{Chef::Config.env['HOME']}/.chef.d"
end
+ end
+
+ before do
+ if windows?
+ Chef::Config.stub(:env).and_return({'SYSTEMDRIVE' => "C:", 'HOMEPATH' => "MyHome"})
+ else
+ Chef::Config.stub(:env).and_return({'HOME' => "/Users/me"})
+ end
+
+ Chef::Config.stub(:path_accessible?).and_return(false)
+ end
+
+ describe "Chef::Config[:cache_path]" do
+ context "when /var/chef exists and is accessible" do
+ it "defaults to /var/chef" do
+ Chef::Config.stub(:path_accessible?).and_return(true)
+ Chef::Config[:cache_path].should == primary_cache_path
+ end
+ end
+
+ context "when /var/chef does not exist and /var is accessible" do
+ it "defaults to /var/chef" do
+ File.stub(:exists?).with(Chef::Config.platform_specific_path("/var/chef")).and_return(false)
+ Chef::Config.stub(:path_accessible?).with(Chef::Config.platform_specific_path("/var")).and_return(true)
+ Chef::Config[:cache_path].should == primary_cache_path
+ end
+ end
+
+ context "when /var/chef does not exist and /var is not accessible" do
+ it "defaults to $HOME/.chef.d" do
+ File.stub(:exists?).with(Chef::Config.platform_specific_path("/var/chef")).and_return(false)
+ Chef::Config.stub(:path_accessible?).with(Chef::Config.platform_specific_path("/var")).and_return(false)
+ Chef::Config[:cache_path].should == secondary_cache_path
+ end
+ end
+
+ context "when /var/chef exists and is not accessible" do
+ it "defaults to $HOME/.chef.d" do
+ File.stub(:exists?).with(Chef::Config.platform_specific_path("/var/chef")).and_return(true)
+ File.stub(:readable?).with(Chef::Config.platform_specific_path("/var/chef")).and_return(true)
+ File.stub(:writable?).with(Chef::Config.platform_specific_path("/var/chef")).and_return(false)
+
+ Chef::Config[:cache_path].should == secondary_cache_path
+ end
+ end
+ end
+
+ it "Chef::Config[:file_backup_path] defaults to /var/chef/backup" do
+ Chef::Config.stub(:cache_path).and_return(Chef::Config.platform_specific_path("/var/chef"))
+ backup_path = Chef::Config.platform_specific_path("#{Chef::Config.cache_path}/backup")
Chef::Config[:file_backup_path].should == backup_path
end
@@ -167,17 +224,15 @@ describe Chef::Config do
end
it "Chef::Config[:data_bag_path] defaults to /var/chef/data_bags" do
+ Chef::Config.stub(:cache_path).and_return(Chef::Config.platform_specific_path("/var/chef"))
data_bag_path =
- Chef::Config.platform_specific_path("/var/chef/data_bags")
+ Chef::Config.platform_specific_path("#{Chef::Config.cache_path}/data_bags")
Chef::Config[:data_bag_path].should == data_bag_path
end
it "Chef::Config[:environment_path] defaults to /var/chef/environments" do
- environment_path = if windows?
- "C:\\chef\\environments"
- else
- "/var/chef/environments"
- end
+ Chef::Config.stub(:cache_path).and_return(Chef::Config.platform_specific_path("/var/chef"))
+ environment_path = Chef::Config.platform_specific_path("#{Chef::Config.cache_path}/environments")
Chef::Config[:environment_path].should == environment_path
end
diff --git a/spec/unit/role_spec.rb b/spec/unit/role_spec.rb
index f36b7f13bd..7410b3a0c6 100644
--- a/spec/unit/role_spec.rb
+++ b/spec/unit/role_spec.rb
@@ -250,6 +250,11 @@ description "like Aliens, but furry"
EOR
describe "when loading from disk" do
+ before do
+ default_cache_path = windows? ? 'C:\chef' : '/var/chef'
+ Chef::Config.stub(:cache_path).and_return(default_cache_path)
+ end
+
it "should return a Chef::Role object from JSON" do
File.should_receive(:exists?).with(File.join(Chef::Config[:role_path], 'lolcat.json')).exactly(1).times.and_return(true)
IO.should_receive(:read).with(File.join(Chef::Config[:role_path], 'lolcat.json')).and_return('{"name": "ceiling_cat", "json_class": "Chef::Role" }')
@@ -325,4 +330,3 @@ EOR
end
end
-
diff --git a/spec/unit/run_lock_spec.rb b/spec/unit/run_lock_spec.rb
index 9738f76650..80140dfcce 100644
--- a/spec/unit/run_lock_spec.rb
+++ b/spec/unit/run_lock_spec.rb
@@ -20,10 +20,12 @@ require 'chef/client'
describe Chef::RunLock do
+ default_cache_path = windows? ? 'C:\chef' : '/var/chef'
default_pid_location = windows? ? 'C:\chef\cache\chef-client-running.pid' : '/var/chef/cache/chef-client-running.pid'
describe "when first created" do
it "locates the lockfile in the file cache path by default" do
+ Chef::Config.stub(:cache_path).and_return(default_cache_path)
run_lock = Chef::RunLock.new(Chef::Config.lockfile)
run_lock.runlock_file.should == default_pid_location
end