summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorJohn Keiser <jkeiser@opscode.com>2014-04-21 07:36:46 -0700
committerJohn Keiser <jkeiser@opscode.com>2014-04-21 07:36:46 -0700
commite908aa35f5b62f646557a9b932189e184fc093e1 (patch)
treef9f75e440b3c4405da10bffdfcc1d263cb204677 /spec
parent09de5c7174277e1d0f1b67dce4cff74daa2cbb1f (diff)
downloadchef-zero-e908aa35f5b62f646557a9b932189e184fc093e1.tar.gz
Support ChefFSDataStore from prior versions
Diffstat (limited to 'spec')
-rw-r--r--spec/run.rb106
1 files changed, 81 insertions, 25 deletions
diff --git a/spec/run.rb b/spec/run.rb
index 01dffe9..d538c2f 100644
--- a/spec/run.rb
+++ b/spec/run.rb
@@ -5,33 +5,89 @@ require 'bundler/setup'
require 'chef_zero/server'
require 'rspec/core'
-server = ChefZero::Server.new(:port => 8889)
-server.start_background
-
-unless ENV['SKIP_PEDANT']
- require 'pedant'
- require 'pedant/opensource'
-
- Pedant.config.suite = 'api'
- Pedant.config[:config_file] = 'spec/support/pedant.rb'
- Pedant.setup([
- '--skip-validation',
- '--skip-authentication',
- '--skip-authorization',
- '--skip-omnibus'
- ])
-
- result = RSpec::Core::Runner.run(Pedant.config.rspec_args)
-else
- require 'net/http'
- response = Net::HTTP.new('127.0.0.1', 8889).get("/environments", { 'Accept' => 'application/json'}).body
- if response =~ /_default/
- result = 0
+tmpdir = nil
+
+def start_server(chef_repo_path)
+ # Create the chef repo
+ Dir.mkdir(chef_repo_path)
+ # 11.6 and below had a bug where it couldn't create the repo children automatically
+ if Chef::VERSION.to_f < 11.8
+ %w(clients cookbooks data_bags environments nodes roles users).each do |child|
+ Dir.mkdir("#{chef_repo_path}/#{child}")
+ end
+ end
+
+ # Start the new server
+ Chef::Config.repo_mode = 'everything'
+ Chef::Config.chef_repo_path = chef_repo_path
+ chef_fs = Chef::ChefFS::Config.new.local_fs
+ data_store = Chef::ChefFS::ChefFSDataStore.new(chef_fs)
+ server = ChefZero::Server.new(:port => 8889, :data_store => data_store)
+ server.start_background
+ server
+end
+
+begin
+ if ENV['CHEF_FS']
+ require 'chef/chef_fs/chef_fs_data_store'
+ require 'chef/chef_fs/config'
+ require 'tmpdir'
+ require 'fileutils'
+ require 'chef/version'
+
+ # Create chef repository
+ tmpdir = Dir.mktmpdir
+ chef_repo_path = "#{tmpdir}/repo"
+ server = start_server(chef_repo_path)
+
+ # Delete everything before each test
+ RSpec.configure do |config|
+ config.before(:each) do
+ # Stop the old server
+ if server
+ server.stop
+ server = nil
+ FileUtils.rm_rf(chef_repo_path)
+ end
+
+ server = start_server(chef_repo_path)
+ end
+ end
+
else
- puts "GET /environments returned #{response}. Expected _default!"
- result = 1
+ server = ChefZero::Server.new(:port => 8889)
+ server.start_background
end
+
+ unless ENV['SKIP_PEDANT']
+ require 'pedant'
+ require 'pedant/opensource'
+
+ Pedant.config.suite = 'api'
+ Pedant.config[:config_file] = 'spec/support/pedant.rb'
+ Pedant.setup([
+ '--skip-knife',
+ '--skip-validation',
+ '--skip-authentication',
+ '--skip-authorization',
+ '--skip-omnibus'
+ ])
+
+ result = RSpec::Core::Runner.run(Pedant.config.rspec_args)
+ else
+ require 'net/http'
+ response = Net::HTTP.new('127.0.0.1', 8889).get("/environments", { 'Accept' => 'application/json'}).body
+ if response =~ /_default/
+ result = 0
+ else
+ puts "GET /environments returned #{response}. Expected _default!"
+ result = 1
+ end
+ end
+
+ server.stop
+ensure
+ FileUtils.remove_entry_secure(tmpdir) if tmpdir
end
-server.stop
exit(result)