-
-
Save amaltson/9bed2b277ac26116182c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat Rakefile | |
require 'rake' | |
require 'rspec/core/rake_task' | |
hosts = %w( | |
atlspf01 | |
atlspf02 | |
atlspf03 | |
atlspf04 | |
) | |
task :spec => 'spec:all' | |
namespace :spec do | |
task :all => hosts.map {|h| 'spec:' + h.split('.')[0] } | |
hosts.each do |host| | |
begin | |
desc "Run serverspec to #{host}" | |
RSpec::Core::RakeTask.new(host) do |t| | |
ENV['TARGET_HOST'] = host | |
t.pattern = "spec/base,cfengine3/*_spec.rb" | |
end | |
rescue | |
end | |
end | |
end | |
$ cat spec/spec_helper.rb | |
require 'serverspec' | |
require 'net/ssh' | |
set :backend, :ssh | |
if ENV['ASK_SUDO_PASSWORD'] | |
begin | |
require 'highline/import' | |
rescue LoadError | |
fail "highline is not available. Try installing it." | |
end | |
set :sudo_password, ask("Enter sudo password: ") { |q| q.echo = false } | |
else | |
set :sudo_password, ENV['SUDO_PASSWORD'] | |
end | |
host = ENV['TARGET_HOST'] | |
options = Net::SSH::Config.for(host) | |
options[:user] ||= Etc.getlogin | |
set :host, options[:host_name] || host | |
set :ssh_options, options | |
$ cat spec/cfengine3/common_spec.rb | |
require 'spec_helper' | |
describe "All server tests" do | |
before(:each) do | |
puts "ServerSpec tests on [#{ENV['TARGET_HOST']}]" | |
end | |
describe package('cfengine-community') do | |
it { should be_installed } | |
end | |
describe command( '/var/cfengine/bin/cf-promises --version') do | |
its(:stdout) { should match /3\.6\.5/ } | |
end | |
describe service( 'cfengine3' ) do | |
it { should be_enabled } | |
end | |
for proc in [ 'execd', 'serverd', 'monitord' ] | |
describe process( "cf-#{proc}" ) do | |
it { should be_running } | |
end | |
end | |
describe port(5308) do | |
it { should be_listening } | |
end | |
end | |
# What does this do? | |
#Results (what host failed?) | |
Run it and I still don't know what host fails. | |
$ rspec | |
ServerSpec tests on [] | |
Password: | |
.ServerSpec tests on [] | |
.ServerSpec tests on [] | |
FServerSpec tests on [] | |
.ServerSpec tests on [] | |
.ServerSpec tests on [] | |
.ServerSpec tests on [] | |
. | |
Failures: | |
1) All server tests Service "cfengine3" should be enabled | |
Failure/Error: it { should be_enabled } | |
expected Service "cfengine3" to be enabled | |
sudo -p 'Password: ' /bin/sh -c chkconfig\ --list\ cfengine3\ \|\ grep\ 3:on | |
# ./spec/cfengine3/common_spec.rb:17:in `block (3 levels) in <top (required)>' | |
Finished in 11.01 seconds (files took 1.28 seconds to load) | |
7 examples, 1 failure | |
Failed examples: | |
rspec ./spec/cfengine3/common_spec.rb:17 # All server tests Service "cfengine3" should be enabled |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment