Skip to content

Commit

Permalink
Merge branch 'windows-ci-breakage'
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsdeleo committed Nov 19, 2012
2 parents d84c505 + 51a06a4 commit 3801dea
Show file tree
Hide file tree
Showing 16 changed files with 86 additions and 38 deletions.
6 changes: 0 additions & 6 deletions Gemfile
Expand Up @@ -7,12 +7,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'
Expand Down
1 change: 0 additions & 1 deletion chef.gemspec
Expand Up @@ -5,7 +5,6 @@ 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.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
Expand Down
2 changes: 1 addition & 1 deletion ci/jenkins_run_tests.bat
Expand Up @@ -2,4 +2,4 @@ set PATH=C:\Ruby192\bin;%PATH%

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
2 changes: 0 additions & 2 deletions spec/functional/knife/cookbook_delete_spec.rb
Expand Up @@ -23,8 +23,6 @@
before(:all) do
@original_config = Chef::Config.hash_dup

Thin::Logging.silent = true

@server = TinyServer::Manager.new
@server.start
end
Expand Down
2 changes: 0 additions & 2 deletions spec/functional/knife/exec_spec.rb
Expand Up @@ -23,8 +23,6 @@
before(:all) do
@original_config = Chef::Config.hash_dup

Thin::Logging.silent = false

@server = TinyServer::Manager.new#(:debug => true)
@server.start
end
Expand Down
1 change: 0 additions & 1 deletion spec/functional/knife/ssh_spec.rb
Expand Up @@ -24,7 +24,6 @@
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
Expand Down
8 changes: 7 additions & 1 deletion spec/functional/resource/cookbook_file_spec.rb
Expand Up @@ -24,7 +24,13 @@
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
Expand Down
13 changes: 10 additions & 3 deletions spec/functional/resource/remote_file_spec.rb
Expand Up @@ -24,7 +24,13 @@

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
Expand All @@ -40,13 +46,14 @@ def create_resource
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

Expand Down
9 changes: 5 additions & 4 deletions spec/functional/tiny_server_spec.rb
Expand Up @@ -37,15 +37,16 @@

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

Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Expand Up @@ -72,6 +72,7 @@ module Shell
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
Expand Down
13 changes: 13 additions & 0 deletions spec/support/chef_helpers.rb
Expand Up @@ -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
15 changes: 11 additions & 4 deletions spec/support/shared/functional/file_resource.rb
Expand Up @@ -146,6 +146,13 @@
# 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)
end

context "when the target file does not exist" do
before do
# Assert starting state is expected
Expand All @@ -162,7 +169,7 @@
end

it "creates the file with the correct content when the :create action is run" do
IO.read(path).should == expected_content
binread(path).should == expected_content
end

it "is marked as updated by last action" do
Expand All @@ -176,7 +183,7 @@
end

it "creates the file with the correct content" do
IO.read(path).should == expected_content
binread(path).should == expected_content
end

it "is marked as updated by last action" do
Expand Down Expand Up @@ -211,7 +218,7 @@ def denied_acl(sid, expected_perms)

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)

Expand All @@ -238,7 +245,7 @@ def denied_acl(sid, expected_perms)

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)

Expand Down
4 changes: 4 additions & 0 deletions spec/support/shared/functional/securable_resource.rb
Expand Up @@ -29,12 +29,16 @@
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
Expand Down
39 changes: 29 additions & 10 deletions spec/tiny_server.rb
Expand Up @@ -17,42 +17,56 @@
#

require 'rubygems'
require 'webrick'
require 'rack'
require 'thin'
#require 'thin'
require 'singleton'
require 'chef/json_compat'
require 'open-uri'
require 'chef/config'

module TinyServer

class Server < Rack::Server

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
Expand All @@ -63,7 +77,10 @@ def url

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
Expand All @@ -84,6 +101,7 @@ def started?

def stop
# yes, this is terrible.
@server.shutdown
@server_thread.kill
@server_thread.join
@server_thread = nil
Expand Down Expand Up @@ -132,7 +150,7 @@ def call(env)
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
Expand All @@ -152,6 +170,7 @@ def initialize(path_spec, response)
end

def matches_request?(uri)
uri = URI.parse(uri).request_uri
@path_spec === uri
end

Expand All @@ -171,7 +190,7 @@ def initialize(response_code=200,data=nil, &block)

def call
data = @data || @block.call
[@response_code, HEADERS, data]
[@response_code, HEADERS, Array(data)]
end

def to_s
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/chef_fs/diff_spec.rb
Expand Up @@ -28,7 +28,7 @@ def remove_date(diff)
diff.gsub(/([+-]{3}.*)\t.*/, '\1 DATE')
end

describe 'diff' do
describe 'diff', :uses_diff => true do
include FileSystemSupport

context 'with two filesystems with all types of difference' do
Expand Down
6 changes: 4 additions & 2 deletions spec/unit/provider/file_spec.rb
Expand Up @@ -342,10 +342,12 @@
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)
Expand All @@ -355,7 +357,7 @@
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
Expand Down

0 comments on commit 3801dea

Please sign in to comment.