Skip to content

Commit

Permalink
initial rspec-puppet
Browse files Browse the repository at this point in the history
  • Loading branch information
dgolja committed May 11, 2014
1 parent e3ee978 commit 7ed5ef3
Show file tree
Hide file tree
Showing 9 changed files with 194 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fixtures:
repositories:
stdlib: "git://github.com/puppetlabs/puppetlabs-stdlib.git"
concat: "git://github.com/puppetlabs/puppetlabs-concat.git"
apt: "git://github.com/puppetlabs/puppetlabs-apt.git"
symlinks:
varnish: "#{source_dir}"
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.pkg
Gemfile.lock
vendor
spec/fixtures
.rspec_system
.bundle
.vagrant
.*sw*

16 changes: 16 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
source ENV['GEM_SOURCE'] || 'https://rubygems.org'

group :development, :test do
gem 'rake', :require => false
gem 'rspec-puppet', :require => false
gem 'puppetlabs_spec_helper', :require => false
gem 'puppet-lint', :require => false
gem 'pry', :require => false
gem 'simplecov', :require => false
end

if puppetversion = ENV['PUPPET_GEM_VERSION']
gem 'puppet', puppetversion, :require => false
else
gem 'puppet', :require => false
end
22 changes: 22 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require 'puppetlabs_spec_helper/rake_tasks'
require 'puppet-lint/tasks/puppet-lint'

PuppetLint.configuration.send("disable_80chars")
PuppetLint.configuration.send('disable_class_parameter_defaults')
PuppetLint.configuration.send('disable_class_inherits_from_params_class')
PuppetLint.configuration.send('disable_documentation')
PuppetLint.configuration.log_format = "%{path}:%{linenumber}:%{check}:%{KIND}:%{message}"
PuppetLint.configuration.fail_on_warnings = true

exclude_paths = [
"pkg/**/*",
"spec/**/*",
]

PuppetLint.configuration.ignore_paths = exclude_paths

desc "Run syntax, lint, and spec tests."
task :test => [
:lint,
:spec,
]
103 changes: 103 additions & 0 deletions spec/classes/varnish_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
require 'spec_helper'

describe 'varnish', :type => :class do
context "on a Debian OS" do
let :facts do
{
:osfamily => 'Debian',
:operatingsystemrelease => '6',
:concat_basedir => '/dne',
:lsbdistid => 'Debian',
:lsbdistcodename => 'precise'
}
end

it { should compile }
it { should contain_class('varnish::install').with('add_repo' => 'true') }
it { should contain_class('varnish::service').with('start' => 'yes') }
it { should contain_class('varnish::shmlog') }
it { should contain_file('varnish-conf').with(
'ensure' => 'present',
'path' => '/etc/default/varnish',
'owner' => 'root',
'group' => 'root',
'mode' => '0644',
'require' => 'Package[varnish]',
'notify' => 'Service[varnish]'
)
}
it { should contain_file('storage-dir').with(
'ensure' => 'directory',
'path' => '/var/lib/varnish-storage',
'require' => 'Package[varnish]'
)
}

context "without shmlog_tempfs" do
let :params do
{ :shmlog_tempfs => false }
end

it { should_not contain_class('varnish::shmlog') }
end

context "default varnish-conf values" do
it { should contain_file('varnish-conf').with_content(/START=yes/) }
it { should contain_file('varnish-conf').with_content(/NFILES=131072/) }
it { should contain_file('varnish-conf').with_content(/MEMLOCK=82000/) }
it { should contain_file('varnish-conf').with_content(/VARNISH_VCL_CONF=\/etc\/varnish\/default\.vcl/) }
it { should contain_file('varnish-conf').with_content(/VARNISH_LISTEN_ADDRESS=/) }
it { should contain_file('varnish-conf').with_content(/VARNISH_LISTEN_PORT=6081/) }
it { should contain_file('varnish-conf').with_content(/VARNISH_ADMIN_LISTEN_ADDRESS=127.0.0.1/) }
it { should contain_file('varnish-conf').with_content(/VARNISH_ADMIN_LISTEN_PORT=6082/) }
it { should contain_file('varnish-conf').with_content(/VARNISH_MIN_THREADS=5/) }
it { should contain_file('varnish-conf').with_content(/VARNISH_MAX_THREADS=500/) }
it { should contain_file('varnish-conf').with_content(/VARNISH_THREAD_TIMEOUT=300/) }
it { should contain_file('varnish-conf').with_content(/VARNISH_STORAGE_FILE=\/var\/lib\/varnish-storage\/varnish_storage\.bin/) }
it { should contain_file('varnish-conf').with_content(/VARNISH_STORAGE_SIZE=1G/) }
it { should contain_file('varnish-conf').with_content(/VARNISH_SECRET_FILE=\/etc\/varnish\/secret/) }
it { should contain_file('varnish-conf').with_content(/VARNISH_STORAGE=\"malloc,\${VARNISH_STORAGE_SIZE}\"/) }
it { should contain_file('varnish-conf').with_content(/VARNISH_TTL=120/) }
it { should contain_file('varnish-conf').with_content(/DAEMON_OPTS=\"-a \${VARNISH_LISTEN_ADDRESS}:\${VARNISH_LISTEN_PORT}/) }

end
end

context "on a RedHat" do
let :facts do
{
:osfamily => 'RedHat',
:concat_basedir => '/dne',
:operatingsystem => 'RedHat'
}
end

it { should compile }
it { should contain_class('varnish::install').with('add_repo' => 'true') }
it { should contain_class('varnish::service').with('start' => 'yes') }
it { should contain_class('varnish::shmlog') }
it { should contain_file('varnish-conf').with(
'ensure' => 'present',
'path' => '/etc/sysconfig/varnish',
'owner' => 'root',
'group' => 'root',
'mode' => '0644',
'require' => 'Package[varnish]',
'notify' => 'Service[varnish]'
)
}
it { should contain_file('storage-dir').with(
'ensure' => 'directory',
'path' => '/var/lib/varnish-storage',
'require' => 'Package[varnish]'
)
}
context "without shmlog_tempfs" do
let :params do
{ :shmlog_tempfs => false }
end

it { should_not contain_class('varnish::shmlog') }
end
end
end
6 changes: 6 additions & 0 deletions spec/classes/varnish_vcl_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require 'spec_helper'

describe 'varnish::vcl', :type => :class do


end
25 changes: 25 additions & 0 deletions spec/defines/acl_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'spec_helper'

describe 'varnish::acl', :type => :define do
let :pre_condition do
'class { "::varnish::vcl": }'
end

let(:title) { 'foo' }
let(:facts) { { :concat_basedir => '/dne' } }

context("expected behaviour") do
let(:params) { { :hosts => ['192.168.10.14'] } }
it { should contain_file('/etc/varnish/includes/acls.vcl') }
it { should contain_concat__fragment('foo-acl') }
end

context("invalid acl title") do
let(:title) { '-wrong_title' }

it 'should cause a failure' do
expect {should raise_error(Puppet::Error, 'Invalid characters in ACL name _wrong-title. Only letters, numbers and underscore are allowed.') }
end
end

end
4 changes: 4 additions & 0 deletions spec/spec.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--format s
--colour
--loadby mtime
--backtrace
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require 'puppetlabs_spec_helper/module_spec_helper'

0 comments on commit 7ed5ef3

Please sign in to comment.