From a65355ef53f432e4d574d2df36142189b02d214d Mon Sep 17 00:00:00 2001 From: Carlos Sanchez Date: Wed, 5 Jun 2013 18:35:34 +0200 Subject: [PATCH] Add specs using puppetlabs_spec_helper and librarian-puppet --- .fixtures.yml | 3 ++ .gitignore | 4 +++ Gemfile | 11 ++++++ Gemfile.lock | 65 ++++++++++++++++++++++++++++++++++++ Puppetfile | 3 ++ Puppetfile.lock | 8 +++++ Rakefile | 18 ++++++++++ spec/classes/nginx_spec.rb | 25 ++++++++++++++ spec/classes/package_spec.rb | 57 +++++++++++++++++++++++++++++++ spec/spec_helper.rb | 1 + 10 files changed, 195 insertions(+) create mode 100644 .fixtures.yml create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 Puppetfile create mode 100644 Puppetfile.lock create mode 100644 Rakefile create mode 100644 spec/classes/nginx_spec.rb create mode 100644 spec/classes/package_spec.rb create mode 100644 spec/spec_helper.rb diff --git a/.fixtures.yml b/.fixtures.yml new file mode 100644 index 0000000..439f1ab --- /dev/null +++ b/.fixtures.yml @@ -0,0 +1,3 @@ +fixtures: + symlinks: + nginx: "#{source_dir}" diff --git a/.gitignore b/.gitignore index 84bfbda..ba7f778 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ files/server_test.crt files/server_test.pem pkg/ +.librarian/ +.tmp/ +pkg/ +spec/fixtures/ diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..d53195d --- /dev/null +++ b/Gemfile @@ -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 diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..b8145a8 --- /dev/null +++ b/Gemfile.lock @@ -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) diff --git a/Puppetfile b/Puppetfile new file mode 100644 index 0000000..03b0752 --- /dev/null +++ b/Puppetfile @@ -0,0 +1,3 @@ +forge 'http://forge.puppetlabs.com' + +mod 'puppetlabs/stdlib', '>=0.1.6' diff --git a/Puppetfile.lock b/Puppetfile.lock new file mode 100644 index 0000000..d949104 --- /dev/null +++ b/Puppetfile.lock @@ -0,0 +1,8 @@ +FORGE + remote: http://forge.puppetlabs.com + specs: + puppetlabs/stdlib (4.1.0) + +DEPENDENCIES + puppetlabs/stdlib (>= 0.1.6) + diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..5a41ab3 --- /dev/null +++ b/Rakefile @@ -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] diff --git a/spec/classes/nginx_spec.rb b/spec/classes/nginx_spec.rb new file mode 100644 index 0000000..3d8c903 --- /dev/null +++ b/spec/classes/nginx_spec.rb @@ -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 diff --git a/spec/classes/package_spec.rb b/spec/classes/package_spec.rb new file mode 100644 index 0000000..6d04ff7 --- /dev/null +++ b/spec/classes/package_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..2c6f566 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1 @@ +require 'puppetlabs_spec_helper/module_spec_helper'