-
-
Save amaltson/e870a3634db587de947d 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 | |
host_run_on = options[:host_name] || host | |
set :host, host_run_on | |
set :ssh_options, options | |
RSpec.configure do |c| | |
c.after(:each) do |example| | |
if example.exception | |
puts "Failed on #{host_run_on}" | |
end | |
end | |
end | |
$ cat spec/cfengine3/common_spec.rb | |
require 'spec_helper' | |
describe "All server tests" do | |
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 | |
[ 'execd', 'serverd', 'monitord' ].each |proc| | |
describe process( "cf-#{proc}" ) do | |
it { should be_running } | |
end | |
end | |
describe port(5308) do | |
it { should be_listening } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment