Add specs using puppetlabs_spec_helper and librarian-puppet
This commit is contained in:
parent
48370340b8
commit
a65355ef53
10 changed files with 195 additions and 0 deletions
3
.fixtures.yml
Normal file
3
.fixtures.yml
Normal file
|
@ -0,0 +1,3 @@
|
|||
fixtures:
|
||||
symlinks:
|
||||
nginx: "#{source_dir}"
|
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -1,3 +1,7 @@
|
|||
files/server_test.crt
|
||||
files/server_test.pem
|
||||
pkg/
|
||||
.librarian/
|
||||
.tmp/
|
||||
pkg/
|
||||
spec/fixtures/
|
||||
|
|
11
Gemfile
Normal file
11
Gemfile
Normal file
|
@ -0,0 +1,11 @@
|
|||
source 'https://rubygems.org'
|
||||
|
||||
group :rake do
|
||||
gem 'puppet', '>=3.0.1'
|
||||
gem 'rspec-puppet', '>=0.1.3'
|
||||
gem 'rake', '>=0.9.2.2'
|
||||
gem 'puppet-lint', '>=0.1.12'
|
||||
gem 'puppetlabs_spec_helper'
|
||||
gem 'puppet-blacksmith'
|
||||
gem 'librarian-puppet-maestrodev'
|
||||
end
|
65
Gemfile.lock
Normal file
65
Gemfile.lock
Normal file
|
@ -0,0 +1,65 @@
|
|||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
diff-lcs (1.2.4)
|
||||
facter (1.7.1)
|
||||
hiera (1.2.1)
|
||||
json_pure
|
||||
highline (1.6.19)
|
||||
json (1.8.0)
|
||||
json_pure (1.8.0)
|
||||
librarian (0.1.0)
|
||||
highline
|
||||
thor (~> 0.15)
|
||||
librarian-puppet-maestrodev (0.9.9.2)
|
||||
json
|
||||
librarian (>= 0.1.0)
|
||||
thor (~> 0.15)
|
||||
metaclass (0.0.1)
|
||||
mime-types (1.23)
|
||||
mocha (0.14.0)
|
||||
metaclass (~> 0.0.1)
|
||||
nokogiri (1.5.9)
|
||||
puppet (3.2.1)
|
||||
facter (~> 1.6)
|
||||
hiera (~> 1.0)
|
||||
rgen (~> 0.6)
|
||||
puppet-blacksmith (1.0.5)
|
||||
nokogiri
|
||||
puppet (>= 2.7.16)
|
||||
puppetlabs_spec_helper (>= 0.3.0)
|
||||
rake
|
||||
rest-client
|
||||
puppet-lint (0.3.2)
|
||||
puppetlabs_spec_helper (0.4.1)
|
||||
mocha (>= 0.10.5)
|
||||
rake
|
||||
rspec (>= 2.9.0)
|
||||
rspec-puppet (>= 0.1.1)
|
||||
rake (10.0.4)
|
||||
rest-client (1.6.7)
|
||||
mime-types (>= 1.16)
|
||||
rgen (0.6.2)
|
||||
rspec (2.13.0)
|
||||
rspec-core (~> 2.13.0)
|
||||
rspec-expectations (~> 2.13.0)
|
||||
rspec-mocks (~> 2.13.0)
|
||||
rspec-core (2.13.1)
|
||||
rspec-expectations (2.13.0)
|
||||
diff-lcs (>= 1.1.3, < 2.0)
|
||||
rspec-mocks (2.13.1)
|
||||
rspec-puppet (0.1.6)
|
||||
rspec
|
||||
thor (0.18.1)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
librarian-puppet-maestrodev
|
||||
puppet (>= 3.0.1)
|
||||
puppet-blacksmith
|
||||
puppet-lint (>= 0.1.12)
|
||||
puppetlabs_spec_helper
|
||||
rake (>= 0.9.2.2)
|
||||
rspec-puppet (>= 0.1.3)
|
3
Puppetfile
Normal file
3
Puppetfile
Normal file
|
@ -0,0 +1,3 @@
|
|||
forge 'http://forge.puppetlabs.com'
|
||||
|
||||
mod 'puppetlabs/stdlib', '>=0.1.6'
|
8
Puppetfile.lock
Normal file
8
Puppetfile.lock
Normal file
|
@ -0,0 +1,8 @@
|
|||
FORGE
|
||||
remote: http://forge.puppetlabs.com
|
||||
specs:
|
||||
puppetlabs/stdlib (4.1.0)
|
||||
|
||||
DEPENDENCIES
|
||||
puppetlabs/stdlib (>= 0.1.6)
|
||||
|
18
Rakefile
Normal file
18
Rakefile
Normal file
|
@ -0,0 +1,18 @@
|
|||
require 'bundler'
|
||||
Bundler.require(:rake)
|
||||
require 'rake/clean'
|
||||
|
||||
CLEAN.include('spec/fixtures/', 'doc', 'pkg')
|
||||
CLOBBER.include('.tmp', '.librarian')
|
||||
|
||||
require 'puppetlabs_spec_helper/rake_tasks'
|
||||
require 'puppet_blacksmith/rake_tasks'
|
||||
|
||||
# use librarian-puppet to manage fixtures instead of .fixtures.yml
|
||||
# offers more possibilities like explicit version management, forge downloads,...
|
||||
task :librarian_spec_prep do
|
||||
sh "librarian-puppet install --path=spec/fixtures/modules/"
|
||||
end
|
||||
task :spec_prep => :librarian_spec_prep
|
||||
|
||||
task :default => [:clean, :spec]
|
25
spec/classes/nginx_spec.rb
Normal file
25
spec/classes/nginx_spec.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'nginx' do
|
||||
|
||||
shared_examples 'linux' do |operatingsystem, user|
|
||||
let(:facts) {{ :kernel => 'linux', :operatingsystem => operatingsystem }}
|
||||
|
||||
it { should contain_service('nginx').with(
|
||||
:ensure => 'running',
|
||||
:enable => true
|
||||
) }
|
||||
|
||||
it { should contain_file('/var/nginx/client_body_temp').with_owner(user) }
|
||||
end
|
||||
|
||||
|
||||
context 'redhat' do
|
||||
it_behaves_like 'linux', 'redhat', 'nginx'
|
||||
end
|
||||
|
||||
context 'debian' do
|
||||
it_behaves_like 'linux', 'debian', 'www-data'
|
||||
end
|
||||
|
||||
end
|
57
spec/classes/package_spec.rb
Normal file
57
spec/classes/package_spec.rb
Normal file
|
@ -0,0 +1,57 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'nginx::package' do
|
||||
|
||||
shared_examples 'redhat' do |operatingsystem|
|
||||
let(:facts) {{ :operatingsystem => operatingsystem }}
|
||||
it { should contain_package('nginx') }
|
||||
it { should contain_package('GeoIP') }
|
||||
it { should contain_package('gd') }
|
||||
it { should contain_package('libXpm') }
|
||||
it { should contain_package('libxslt') }
|
||||
it { should contain_yumrepo('nginx-release').with_enabled('1') }
|
||||
end
|
||||
|
||||
shared_examples 'debian' do |operatingsystem|
|
||||
let(:facts) {{ :operatingsystem => operatingsystem }}
|
||||
it { should contain_file('/etc/apt/sources.list.d/nginx.list') }
|
||||
end
|
||||
|
||||
shared_examples 'suse' do |operatingsystem|
|
||||
let(:facts) {{ :operatingsystem => operatingsystem }}
|
||||
it { should contain_package('nginx-0.8') }
|
||||
it { should contain_package('apache2') }
|
||||
it { should contain_package('apache2-itk') }
|
||||
it { should contain_package('apache2-utils') }
|
||||
it { should contain_package('gd') }
|
||||
end
|
||||
|
||||
|
||||
context 'RedHat' do
|
||||
it_behaves_like 'redhat', 'centos'
|
||||
it_behaves_like 'redhat', 'fedora'
|
||||
it_behaves_like 'redhat', 'rhel'
|
||||
it_behaves_like 'redhat', 'redhat'
|
||||
it_behaves_like 'redhat', 'scientific'
|
||||
end
|
||||
|
||||
context 'amazon' do
|
||||
let(:facts) {{ :operatingsystem => 'amazon' }}
|
||||
it { should contain_package('nginx') }
|
||||
end
|
||||
|
||||
context 'debian' do
|
||||
it_behaves_like 'debian', 'debian'
|
||||
it_behaves_like 'debian', 'ubuntu'
|
||||
end
|
||||
|
||||
context 'suse' do
|
||||
it_behaves_like 'suse', 'opensuse'
|
||||
it_behaves_like 'suse', 'suse'
|
||||
end
|
||||
|
||||
context 'other' do
|
||||
let(:facts) {{ :operatingsystem => 'xxx' }}
|
||||
it { expect { subject }.to raise_error(Puppet::Error, /Module nginx is not supported on xxx/) }
|
||||
end
|
||||
end
|
1
spec/spec_helper.rb
Normal file
1
spec/spec_helper.rb
Normal file
|
@ -0,0 +1 @@
|
|||
require 'puppetlabs_spec_helper/module_spec_helper'
|
Loading…
Reference in a new issue