Skip to content

Commit

Permalink
Working beaker serverspec & rspec tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasmeeus committed Nov 30, 2015
1 parent f8e7e60 commit 4e3be15
Show file tree
Hide file tree
Showing 13 changed files with 212 additions and 21 deletions.
9 changes: 8 additions & 1 deletion .fixtures.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
fixtures:
symlinks:
"apache": "#{source_dir}"
apache: "#{source_dir}"
repositories:
concat:
repo: 'https://github.com/cegeka/puppet-concat.git'
stdlib:
repo: 'https://github.com/cegeka/puppet-stdlib.git'
collectd:
repo: 'https://github.com/cegeka/puppet-collectd.git'
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
/.project
log
Gemfile.lock
.DS_Store
spec/fixtures/
10 changes: 10 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
source 'https://rubygems.org'

gem 'fpm', '0.3.11'
gem 'puppet', '3.8.1'
gem 'puppet-lint', '1.1.0'
gem 'rspec-puppet', '2.2.0'
gem 'rake', '0.9.2.2'
gem 'ci_reporter', '1.8.4'
gem 'puppetlabs_spec_helper'
gem 'beaker-rspec'
12 changes: 1 addition & 11 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,11 +1 @@
require 'rubygems'
require 'rake'

task_dir = File.expand_path("../tasks", __FILE__)

FileList["#{task_dir}/**/*.rake"].each { |fn| load fn }

desc "Default task prints the available targets."
task :default do
sh %{rake -T}
end
require 'puppetlabs_spec_helper/rake_tasks'
29 changes: 29 additions & 0 deletions spec/acceptance/apache_access_restriction.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'spec_helper_acceptance'

describe 'apache::vhost_access_restriction' do

describe 'running puppet code' do
it 'should work with no errors' do
pp = <<-EOS
include apache
apache::vhost { 'www.example.com':
ensure => present,
}
apache::vhost_access_restriction { 'www.example.com':
vhost => 'www.example.com',
folder => '/var/www/vhosts/www.example.com/htdocs',
allow_from => '127.0.0.1',
}
EOS

# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end

describe file '/var/www/vhosts/www.example.com/conf/00-vhost_access_restriction-www.example.com.conf' do
it { is_expected.to be_file }
its(:content) { should match /Allow from/ }
end
end
end
32 changes: 32 additions & 0 deletions spec/acceptance/apache_proxy_pass_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'spec_helper_acceptance'

describe 'apache::proxypass' do

describe 'running puppet code' do
it 'should work with no errors' do
pp = <<-EOS
include apache
apache::vhost { 'www.example.com':
ensure => present,
}
apache::proxypass { "proxy legacy dir to legacy server":
ensure => present,
location => "/legacy/",
url => "http://legacyserver.example.com",
params => ["retry=5", "ttl=120"],
vhost => "www.example.com",
proxy_config => ['ProxyPreserveHost On']
}
EOS

# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end

describe file '/var/www/vhosts/www.example.com/conf/proxypass-proxy_legacy_dir_to_legacy_server.conf' do
it { is_expected.to be_file }
its(:content) { should match /ProxyPass/ }
end
end
end
29 changes: 29 additions & 0 deletions spec/acceptance/apache_redirect_match_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'spec_helper_acceptance'

describe 'apache::redirectmatch' do

describe 'running puppet code' do
it 'should work with no errors' do
pp = <<-EOS
include apache
apache::vhost { 'www.example.com':
ensure => present,
}
apache::redirectmatch { "example":
regex => "^/(foo|bar)",
url => "http://foobar.example.com/",
vhost => "www.example.com",
}
EOS

# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end

describe file '/var/www/vhosts/www.example.com/conf/redirect-example.conf' do
it { is_expected.to be_file }
its(:content) { should match /RedirectMatch/ }
end
end
end
26 changes: 26 additions & 0 deletions spec/acceptance/apache_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'spec_helper_acceptance'

describe 'apache' do

describe 'running puppet code' do
it 'should work with no errors' do
pp = <<-EOS
include apache
EOS

# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end


describe port(80) do
it { is_expected.to be_listening }
end

describe service('httpd') do
it { is_expected.to be_enabled }
it { is_expected.to be_running }
end
end
end
24 changes: 24 additions & 0 deletions spec/acceptance/apache_vhost_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'spec_helper_acceptance'

describe 'apache::vhost' do

describe 'running puppet code' do
it 'should work with no errors' do
pp = <<-EOS
include apache
apache::vhost { 'www.example.com':
ensure => present,
}
EOS

# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end

describe file '/etc/httpd/sites-enabled/www.example.com' do
it { is_expected.to be_file }
its(:content) { should match /ServerName www.example.com/ }
end
end
end
15 changes: 15 additions & 0 deletions spec/acceptance/nodesets/default.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
HOSTS:
centos-66-x64:
roles:
- master
platform: el-6-x86_64
box : puppetlabs/centos-6.6-64-nocm
box_url : https://atlas.hashicorp.com/puppetlabs/centos-6.6-64-nocm
hypervisor: vagrant
centos-70-x64:
platform: el-7-x86_64
box : puppetlabs/centos-7.0-64-nocm
box_url : https://atlas.hashicorp.com/puppetlabs/centos-7.0-64-nocm
hypervisor: vagrant
CONFIG:
type: foss
33 changes: 33 additions & 0 deletions spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require 'rake'
require 'puppetlabs_spec_helper/rake_tasks'
require 'beaker-rspec'

Rake::Task[:spec_prep].invoke

hosts.each do |host|
# Install Puppet
on host, install_puppet
end

RSpec.configure do |c|
module_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
module_name = module_root.split('/').last
dependencies_path = module_root + '/spec/fixtures/modules'

# Readable test descriptions
c.formatter = :documentation

# Configure all nodes in nodeset
c.before :suite do
# Install module
puppet_module_install(:source => module_root, :module_name => module_name)

# Install dependencies
Dir.foreach(dependencies_path) do |dependency|
next if dependency == '.' or dependency == '..'
dependency_source = dependencies_path+'/'+dependency
puppet_module_install(:source => dependency_source, :module_name => dependency)
end

end
end
8 changes: 0 additions & 8 deletions tasks/Gemfile

This file was deleted.

2 changes: 1 addition & 1 deletion tasks/rake/spec.rake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'rspec/core/rake_task'

require 'yaml'
require File.expand_path('../../env', __FILE__)

desc "Run puppet module RSpec tests"
Expand Down

0 comments on commit 4e3be15

Please sign in to comment.