summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordanielsdeleo <dan@opscode.com>2012-11-20 14:23:06 -0800
committerdanielsdeleo <dan@opscode.com>2012-11-20 14:23:06 -0800
commit618eb8d4fb4e8044b370be5d3f32b4e3a8ab1d5f (patch)
tree9fa270eccc5534c62dd0256cd63a306f0148de83
parent6a3afe5b6cff92187ac61c356ab3a9161ed29c06 (diff)
downloadchef-618eb8d4fb4e8044b370be5d3f32b4e3a8ab1d5f.tar.gz
backport win functional test fixes to 10-stablewindows-ci-10-stable
-rw-r--r--chef/Gemfile6
-rw-r--r--chef/chef.gemspec3
-rw-r--r--chef/spec/functional/knife/cookbook_delete_spec.rb2
-rw-r--r--chef/spec/functional/knife/exec_spec.rb2
-rw-r--r--chef/spec/functional/knife/ssh_spec.rb1
-rw-r--r--chef/spec/functional/resource/cookbook_file_spec.rb8
-rw-r--r--chef/spec/functional/resource/remote_file_spec.rb13
-rw-r--r--chef/spec/functional/tiny_server_spec.rb9
-rw-r--r--chef/spec/spec_helper.rb1
-rw-r--r--chef/spec/support/chef_helpers.rb13
-rw-r--r--chef/spec/support/shared/functional/file_resource.rb52
-rw-r--r--chef/spec/support/shared/functional/securable_resource.rb4
-rw-r--r--chef/spec/tiny_server.rb39
-rw-r--r--chef/spec/unit/provider/file_spec.rb6
-rw-r--r--ci/jenkins_run_tests.bat2
15 files changed, 119 insertions, 42 deletions
diff --git a/chef/Gemfile b/chef/Gemfile
index 858484d83c..b912e8d7b9 100644
--- a/chef/Gemfile
+++ b/chef/Gemfile
@@ -8,12 +8,6 @@ gem "ronn"
group(:development, :test) do
gem 'rack'
- gem 'thin'
-
- # Eventmachine 1.0.0 is causing functional test failures on Solaris
- # 9 SPARC. Pinning em to 0.12.10 solves this issue until we can
- # replace thin with webrat or some other alternative.
- gem 'eventmachine', '0.12.10', :platforms => :ruby
gem 'ruby-shadow', :platforms => :ruby unless RUBY_PLATFORM.downcase.match(/(darwin|freebsd)/)
# gem 'awesome_print'
diff --git a/chef/chef.gemspec b/chef/chef.gemspec
index e34c74fa6f..9b9679a3e3 100644
--- a/chef/chef.gemspec
+++ b/chef/chef.gemspec
@@ -5,8 +5,7 @@ Gem::Specification.new do |s|
s.name = 'chef'
s.version = Chef::VERSION
s.platform = Gem::Platform::RUBY
- s.has_rdoc = true
- s.extra_rdoc_files = ["README.rdoc", "LICENSE" ]
+ s.extra_rdoc_files = ["README.md", "CONTRIBUTING.md", "LICENSE" ]
s.summary = "A systems integration framework, built to bring the benefits of configuration management to your entire infrastructure."
s.description = s.summary
s.author = "Adam Jacob"
diff --git a/chef/spec/functional/knife/cookbook_delete_spec.rb b/chef/spec/functional/knife/cookbook_delete_spec.rb
index 54081263f0..ef38cb2e1f 100644
--- a/chef/spec/functional/knife/cookbook_delete_spec.rb
+++ b/chef/spec/functional/knife/cookbook_delete_spec.rb
@@ -23,8 +23,6 @@ describe Chef::Knife::CookbookDelete do
before(:all) do
@original_config = Chef::Config.hash_dup
- Thin::Logging.silent = true
-
@server = TinyServer::Manager.new
@server.start
end
diff --git a/chef/spec/functional/knife/exec_spec.rb b/chef/spec/functional/knife/exec_spec.rb
index ab3f38ac94..f979a44f33 100644
--- a/chef/spec/functional/knife/exec_spec.rb
+++ b/chef/spec/functional/knife/exec_spec.rb
@@ -23,8 +23,6 @@ describe Chef::Knife::Exec do
before(:all) do
@original_config = Chef::Config.hash_dup
- Thin::Logging.silent = false
-
@server = TinyServer::Manager.new#(:debug => true)
@server.start
end
diff --git a/chef/spec/functional/knife/ssh_spec.rb b/chef/spec/functional/knife/ssh_spec.rb
index 8f87e53bf7..696fd58c4d 100644
--- a/chef/spec/functional/knife/ssh_spec.rb
+++ b/chef/spec/functional/knife/ssh_spec.rb
@@ -24,7 +24,6 @@ describe Chef::Knife::Ssh do
before(:all) do
@original_config = Chef::Config.hash_dup
Chef::Knife::Ssh.load_deps
- Thin::Logging.silent = true
@server = TinyServer::Manager.new
@server.start
end
diff --git a/chef/spec/functional/resource/cookbook_file_spec.rb b/chef/spec/functional/resource/cookbook_file_spec.rb
index adc1f7eef8..684dd85a12 100644
--- a/chef/spec/functional/resource/cookbook_file_spec.rb
+++ b/chef/spec/functional/resource/cookbook_file_spec.rb
@@ -24,7 +24,13 @@ describe Chef::Resource::CookbookFile do
let(:file_base) { 'cookbook_file_spec' }
let(:source) { 'java.response' }
let(:cookbook_name) { 'java' }
- let(:expected_content) { IO.read(File.join(CHEF_SPEC_DATA, 'cookbooks', 'java', 'files', 'default', 'java.response')) }
+ let(:expected_content) do
+ content = File.open(File.join(CHEF_SPEC_DATA, 'cookbooks', 'java', 'files', 'default', 'java.response'), "rb") do |f|
+ f.read
+ end
+ content.force_encoding(Encoding::BINARY) if content.respond_to?(:force_encoding)
+ content
+ end
def create_resource
# set up cookbook collection for this run to use, based on our
diff --git a/chef/spec/functional/resource/remote_file_spec.rb b/chef/spec/functional/resource/remote_file_spec.rb
index e695e8feae..998255e720 100644
--- a/chef/spec/functional/resource/remote_file_spec.rb
+++ b/chef/spec/functional/resource/remote_file_spec.rb
@@ -24,7 +24,13 @@ describe Chef::Resource::RemoteFile do
let(:file_base) { "remote_file_spec" }
let(:source) { 'http://localhost:9000/nyan_cat.png' }
- let(:expected_content) { IO.read(File.join(CHEF_SPEC_DATA, 'remote_file', 'nyan_cat.png')) }
+ let(:expected_content) do
+ content = File.open(File.join(CHEF_SPEC_DATA, 'remote_file', 'nyan_cat.png'), "rb") do |f|
+ f.read
+ end
+ content.force_encoding(Encoding::BINARY) if content.respond_to?(:force_encoding)
+ content
+ end
def create_resource
node = Chef::Node.new
@@ -40,13 +46,14 @@ describe Chef::Resource::RemoteFile do
end
before(:all) do
- Thin::Logging.silent = false
@server = TinyServer::Manager.new
@server.start
@api = TinyServer::API.instance
@api.clear
@api.get("/nyan_cat.png", 200) {
- IO.read(File.join(CHEF_SPEC_DATA, 'remote_file', 'nyan_cat.png'))
+ File.open(File.join(CHEF_SPEC_DATA, 'remote_file', 'nyan_cat.png'), "rb") do |f|
+ f.read
+ end
}
end
diff --git a/chef/spec/functional/tiny_server_spec.rb b/chef/spec/functional/tiny_server_spec.rb
index 0cfef4305f..68ab9e7294 100644
--- a/chef/spec/functional/tiny_server_spec.rb
+++ b/chef/spec/functional/tiny_server_spec.rb
@@ -37,15 +37,16 @@ describe TinyServer::API do
it "creates a route for a GET request" do
@api.get('/foo/bar', 200, 'hello foobar')
- response = @api.call("REQUEST_METHOD" => "GET", "REQUEST_URI" => '/foo/bar')
- response.should == [200, {'Content-Type' => 'application/json'}, 'hello foobar']
+ # WEBrick gives you the full URI with host, Thin only gave the part after scheme+host+port
+ response = @api.call("REQUEST_METHOD" => "GET", "REQUEST_URI" => 'http://localhost:1974/foo/bar')
+ response.should == [200, {'Content-Type' => 'application/json'}, [ 'hello foobar' ]]
end
it "creates a route for a request with a block" do
block_called = false
@api.get('/bar/baz', 200) { block_called = true; 'hello barbaz' }
- response = @api.call("REQUEST_METHOD" => "GET", "REQUEST_URI" => '/bar/baz')
- response.should == [200, {'Content-Type' => 'application/json'}, 'hello barbaz']
+ response = @api.call("REQUEST_METHOD" => "GET", "REQUEST_URI" => 'http://localhost:1974/bar/baz')
+ response.should == [200, {'Content-Type' => 'application/json'}, [ 'hello barbaz' ]]
block_called.should be_true
end
diff --git a/chef/spec/spec_helper.rb b/chef/spec/spec_helper.rb
index 32bddeb415..3611297aa6 100644
--- a/chef/spec/spec_helper.rb
+++ b/chef/spec/spec_helper.rb
@@ -71,6 +71,7 @@ RSpec.configure do |config|
config.filter_run_excluding :ruby_19_only => true unless ruby_19?
config.filter_run_excluding :requires_root => true unless ENV['USER'] == 'root'
config.filter_run_excluding :requires_unprivileged_user => true if ENV['USER'] == 'root'
+ config.filter_run_excluding :uses_diff => true unless has_diff?
config.run_all_when_everything_filtered = true
config.treat_symbols_as_metadata_keys_with_true_values = true
diff --git a/chef/spec/support/chef_helpers.rb b/chef/spec/support/chef_helpers.rb
index 77f5fc7669..77cbe5b5cb 100644
--- a/chef/spec/support/chef_helpers.rb
+++ b/chef/spec/support/chef_helpers.rb
@@ -50,3 +50,16 @@ def make_tmpname(prefix_suffix, n)
path << "-#{n}" if n
path << suffix
end
+
+# NOTE:
+# This is a temporary fix to get tests passing on systems that have no `diff`
+# until we can replace shelling out to `diff` with ruby diff-lcs
+def has_diff?
+ begin
+ diff_cmd = Mixlib::ShellOut.new("diff -v")
+ diff_cmd.run_command
+ true
+ rescue Errno::ENOENT
+ false
+ end
+end
diff --git a/chef/spec/support/shared/functional/file_resource.rb b/chef/spec/support/shared/functional/file_resource.rb
index 631a5ed742..c3d3cc763d 100644
--- a/chef/spec/support/shared/functional/file_resource.rb
+++ b/chef/spec/support/shared/functional/file_resource.rb
@@ -78,20 +78,50 @@ shared_examples_for "a file resource" do
# note the stripping of the drive letter from the tmpdir on windows
let(:backup_glob) { File.join(CHEF_SPEC_BACKUP_PATH, Dir.tmpdir.sub(/^([A-Za-z]:)/, ""), "#{file_base}*") }
+ def binread(file)
+ content = File.open(file, "rb") do |f|
+ f.read
+ end
+ content.force_encoding(Encoding::BINARY) if "".respond_to?(:force_encoding)
+ content
+ end
+
context "when the target file does not exist" do
it "creates the file when the :create action is run" do
resource.run_action(:create)
File.should exist(path)
end
- it "creates the file with the correct content when the :create action is run" do
- resource.run_action(:create)
- IO.read(path).should == expected_content
+ describe "when running action :create" do
+ before do
+ resource.run_action(:create)
+ end
+
+ it "creates the file when the :create action is run" do
+ File.should exist(path)
+ end
+
+ it "creates the file with the correct content when the :create action is run" do
+ binread(path).should == expected_content
+ end
+
+ it "is marked as updated by last action" do
+ resource.should be_updated_by_last_action
+ end
end
- it "creates the file with the correct content when the :create_if_missing action is run" do
- resource.run_action(:create_if_missing)
- IO.read(path).should == expected_content
+ describe "when running action :create_if_missing" do
+ before do
+ resource.run_action(:create_if_missing)
+ end
+
+ it "creates the file with the correct content" do
+ binread(path).should == expected_content
+ end
+
+ it "is marked as updated by last action" do
+ resource.should be_updated_by_last_action
+ end
end
it "deletes the file when the :delete action is run" do
@@ -112,7 +142,10 @@ shared_examples_for "a file resource" do
context "when the target file has the wrong content" do
before(:each) do
- File.open(path, "w") { |f| f.print "This is so wrong!!!" }
+ File.open(path, "wb") { |f| f.print "This is so wrong!!!" }
+ #now = Time.now.to_i
+ #File.utime(now - 9000, now - 9000, path)
+
@expected_mtime = File.stat(path).mtime
@expected_checksum = sha256_checksum(path)
end
@@ -136,7 +169,10 @@ shared_examples_for "a file resource" do
context "when the target file has the correct content" do
before(:each) do
- File.open(path, "w") { |f| f.print expected_content }
+ File.open(path, "wb") { |f| f.print expected_content }
+ # now = Time.now.to_i
+ # File.utime(now - 9000, now - 9000, path)
+
@expected_mtime = File.stat(path).mtime
@expected_atime = File.stat(path).atime
@expected_checksum = sha256_checksum(path)
diff --git a/chef/spec/support/shared/functional/securable_resource.rb b/chef/spec/support/shared/functional/securable_resource.rb
index 2eeb16c784..2e5797bc8f 100644
--- a/chef/spec/support/shared/functional/securable_resource.rb
+++ b/chef/spec/support/shared/functional/securable_resource.rb
@@ -29,12 +29,16 @@ shared_context "setup correct permissions" do
before :each do
File.chown(Etc.getpwnam('nobody').uid, 1337, path)
File.chmod(0776, path)
+ now = Time.now.to_i
+ File.utime(now - 9000, now - 9000, path)
end
end
context "without root", :requires_unprivileged_user do
before :each do
File.chmod(0776, path)
+ now = Time.now.to_i
+ File.utime(now - 9000, now - 9000, path)
end
end
end
diff --git a/chef/spec/tiny_server.rb b/chef/spec/tiny_server.rb
index ae8518097b..ba75cd57c1 100644
--- a/chef/spec/tiny_server.rb
+++ b/chef/spec/tiny_server.rb
@@ -17,11 +17,13 @@
#
require 'rubygems'
+require 'webrick'
require 'rack'
-require 'thin'
+#require 'thin'
require 'singleton'
require 'chef/json_compat'
require 'open-uri'
+require 'chef/config'
module TinyServer
@@ -29,30 +31,42 @@ module TinyServer
attr_writer :app
- def self.run(options=nil, &block)
+ def self.setup(options=nil, &block)
tiny_app = new(options)
app_code = Rack::Builder.new(&block).to_app
tiny_app.app = app_code
- tiny_app.start
+ tiny_app
+ end
+
+ def shutdown
+ server.shutdown
end
end
class Manager
- DEFAULT_OPTIONS = {:server => 'thin', :Port => 9000, :Host => 'localhost', :environment => :none}
+ # 5 == debug, 3 == warning
+ LOGGER = WEBrick::Log.new(STDOUT, 3)
+ DEFAULT_OPTIONS = {
+ :server => 'webrick',
+ :Port => 9000,
+ :Host => 'localhost',
+ :environment => :none,
+ :Logger => LOGGER,
+ :AccessLog => [] # Remove this option to enable the access log when debugging.
+ }
def initialize(options=nil)
@options = options ? DEFAULT_OPTIONS.merge(options) : DEFAULT_OPTIONS
@creator = caller.first
-
- Thin::Logging.silent = !@options[:debug]
end
def start
@server_thread = Thread.new do
- @server = Server.run(@options) do
+ @server = Server.setup(@options) do
run API.instance
end
+ @server.start
end
block_until_started
end
@@ -63,7 +77,10 @@ module TinyServer
def block_until_started
200.times do
- return true if started?
+ if started?
+ raise "ivar weirdness" if @server.nil?
+ return true
+ end
end
raise "TinyServer failed to boot :/"
end
@@ -84,6 +101,7 @@ module TinyServer
def stop
# yes, this is terrible.
+ @server.shutdown
@server_thread.kill
@server_thread.join
@server_thread = nil
@@ -132,7 +150,7 @@ module TinyServer
debug_info = {:message => "no data matches the request for #{env['REQUEST_URI']}",
:available_routes => @routes, :request => env}
# Uncomment me for glorious debugging
- #pp :not_found => debug_info
+ # pp :not_found => debug_info
[404, {'Content-Type' => 'application/json'}, debug_info.to_json]
end
end
@@ -152,6 +170,7 @@ module TinyServer
end
def matches_request?(uri)
+ uri = URI.parse(uri).request_uri
@path_spec === uri
end
@@ -171,7 +190,7 @@ module TinyServer
def call
data = @data || @block.call
- [@response_code, HEADERS, data]
+ [@response_code, HEADERS, Array(data)]
end
def to_s
diff --git a/chef/spec/unit/provider/file_spec.rb b/chef/spec/unit/provider/file_spec.rb
index 9f5ad3a8f8..23352a5124 100644
--- a/chef/spec/unit/provider/file_spec.rb
+++ b/chef/spec/unit/provider/file_spec.rb
@@ -342,10 +342,12 @@ describe Chef::Provider::File do
end
it "should call action create if the does not file exist" do
- @resource.path("/tmp/non_existant_file")
+ @resource.path("/tmp/example-dir/non_existant_file")
@provider = Chef::Provider::File.new(@resource, @run_context)
@provider.should_receive(:diff_current_from_content).and_return("")
::File.stub!(:exists?).with(@resource.path).and_return(false)
+ ::File.stub!(:directory?).with("/tmp/example-dir/non_existant_file").and_return(false)
+ ::File.stub!(:directory?).with("/tmp/example-dir").and_return(true)
@provider.stub!(:update_new_file_state)
io = StringIO.new
File.should_receive(:open).with(@provider.new_resource.path, "w+").and_yield(io)
@@ -355,7 +357,7 @@ describe Chef::Provider::File do
end
end
- describe "when a diff is requested" do
+ describe "when a diff is requested", :uses_diff => true do
before(:each) do
@original_config = Chef::Config.hash_dup
diff --git a/ci/jenkins_run_tests.bat b/ci/jenkins_run_tests.bat
index 445798090c..9bcec5c445 100644
--- a/ci/jenkins_run_tests.bat
+++ b/ci/jenkins_run_tests.bat
@@ -5,4 +5,4 @@ cd chef
ruby -v
call bundle install --binstubs --path vendor/bundle || ( call rm Gemfile.lock && call bundle install --binstubs --path vendor/bundle )
-ruby bin\rspec -r rspec_junit_formatter -f RspecJunitFormatter -o test.xml -f documentation spec/unit spec/functional
+ruby bin\rspec -r rspec_junit_formatter -f RspecJunitFormatter -o test.xml -f documentation spec/functional spec/unit