From 52e6aa49c729920bcf20dc5bbe7424aafbdc0a1b Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Wed, 4 Sep 2013 15:11:36 -0400 Subject: [PATCH] Add basic rspec-system tests. This adds some really basic system tests so that we can test that various refactorings work correctly and make life easier for you before submitting. --- .nodeset.yml | 35 +++++++++++++++++++++++++++ Gemfile | 3 +++ Rakefile | 1 + spec/spec_helper_system.rb | 27 +++++++++++++++++++++ spec/system/basic_spec.rb | 13 ++++++++++ spec/system/class_spec.rb | 20 +++++++++++++++ spec/system/nginx_mail_spec.rb | 38 +++++++++++++++++++++++++++++ spec/system/nginx_proxy_spec.rb | 43 +++++++++++++++++++++++++++++++++ spec/system/nginx_vhost_spec.rb | 27 +++++++++++++++++++++ 9 files changed, 207 insertions(+) create mode 100644 .nodeset.yml create mode 100644 spec/spec_helper_system.rb create mode 100644 spec/system/basic_spec.rb create mode 100644 spec/system/class_spec.rb create mode 100644 spec/system/nginx_mail_spec.rb create mode 100644 spec/system/nginx_proxy_spec.rb create mode 100644 spec/system/nginx_vhost_spec.rb diff --git a/.nodeset.yml b/.nodeset.yml new file mode 100644 index 0000000..cbd0d57 --- /dev/null +++ b/.nodeset.yml @@ -0,0 +1,35 @@ +--- +default_set: 'centos-64-x64' +sets: + 'centos-59-x64': + nodes: + "main.foo.vm": + prefab: 'centos-59-x64' + 'centos-64-x64': + nodes: + "main.foo.vm": + prefab: 'centos-64-x64' + 'fedora-18-x64': + nodes: + "main.foo.vm": + prefab: 'fedora-18-x64' + 'debian-607-x64': + nodes: + "main.foo.vm": + prefab: 'debian-607-x64' + 'debian-70rc1-x64': + nodes: + "main.foo.vm": + prefab: 'debian-70rc1-x64' + 'ubuntu-server-10044-x64': + nodes: + "main.foo.vm": + prefab: 'ubuntu-server-10044-x64' + 'ubuntu-server-12042-x64': + nodes: + "main.foo.vm": + prefab: 'ubuntu-server-12042-x64' + 'sles-11sp1-x64': + nodes: + "main.foo.vm": + prefab: 'sles-11sp1-x64' diff --git a/Gemfile b/Gemfile index d53195d..722e7fa 100644 --- a/Gemfile +++ b/Gemfile @@ -8,4 +8,7 @@ group :rake do gem 'puppetlabs_spec_helper' gem 'puppet-blacksmith' gem 'librarian-puppet-maestrodev' + gem 'rspec-system-puppet', :require => false + gem 'serverspec', :require => false + gem 'rspec-system-serverspec', :require => false end diff --git a/Rakefile b/Rakefile index 5a41ab3..e0913e5 100644 --- a/Rakefile +++ b/Rakefile @@ -7,6 +7,7 @@ CLOBBER.include('.tmp', '.librarian') require 'puppetlabs_spec_helper/rake_tasks' require 'puppet_blacksmith/rake_tasks' +require 'rspec-system/rake_task' # use librarian-puppet to manage fixtures instead of .fixtures.yml # offers more possibilities like explicit version management, forge downloads,... diff --git a/spec/spec_helper_system.rb b/spec/spec_helper_system.rb new file mode 100644 index 0000000..0c5eeb9 --- /dev/null +++ b/spec/spec_helper_system.rb @@ -0,0 +1,27 @@ +require 'rspec-system/spec_helper' +require 'rspec-system-puppet/helpers' +require 'rspec-system-serverspec/helpers' +include Serverspec::Helper::RSpecSystem +include Serverspec::Helper::DetectOS +include RSpecSystemPuppet::Helpers + +RSpec.configure do |c| + # Project root + proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) + + # Enable colour + c.tty = true + + c.include RSpecSystemPuppet::Helpers + + # This is where we 'setup' the nodes before running our tests + c.before :suite do + # Install puppet + puppet_install + + # Install modules and dependencies + puppet_module_install(:source => proj_root, :module_name => 'nginx') + shell('puppet module install puppetlabs-apt') + shell('puppet module install puppetlabs-stdlib') + end +end diff --git a/spec/system/basic_spec.rb b/spec/system/basic_spec.rb new file mode 100644 index 0000000..216f0c7 --- /dev/null +++ b/spec/system/basic_spec.rb @@ -0,0 +1,13 @@ +require 'spec_helper_system' + +# Here we put the more basic fundamental tests, ultra obvious stuff. +describe "basic tests:" do + context 'make sure we have copied the module across' do + # No point diagnosing any more if the module wasn't copied properly + context shell 'ls /etc/puppet/modules/nginx' do + its(:stdout) { should =~ /Modulefile/ } + its(:stderr) { should be_empty } + its(:exit_code) { should be_zero } + end + end +end diff --git a/spec/system/class_spec.rb b/spec/system/class_spec.rb new file mode 100644 index 0000000..ca58d3f --- /dev/null +++ b/spec/system/class_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper_system' + +describe "nginx class:" do + context 'should run successfully' do + pp = "class { 'nginx': }" + + context puppet_apply(pp) do + its(:stderr) { should be_empty } + its(:exit_code) { should_not == 1 } + its(:refresh) { should be_nil } + its(:stderr) { should be_empty } + its(:exit_code) { should be_zero } + end + end + + describe service('nginx') do + it { should be_running } + end + +end diff --git a/spec/system/nginx_mail_spec.rb b/spec/system/nginx_mail_spec.rb new file mode 100644 index 0000000..22d9257 --- /dev/null +++ b/spec/system/nginx_mail_spec.rb @@ -0,0 +1,38 @@ +require 'spec_helper_system' + +describe "nginx::resource::mailhost define:" do + context 'should run successfully' do + + pp = " + class { 'nginx': + mail => true, + } + nginx::resource::vhost { 'www.puppetlabs.com': + ensure => present, + www_root => '/var/www/www.puppetlabs.com', + } + nginx::resource::mailhost { 'domain1.example': + ensure => present, + auth_http => 'localhost/cgi-bin/auth', + protocol => 'smtp', + listen_port => 587, + ssl_port => 465, + xclient => 'off', + } + " + + context puppet_apply(pp) do + its(:exit_code) { should_not == 1 } + its(:refresh) { should be_nil } + # Not until deprecated variables fixed. + #its(:stderr) { should be_empty } + its(:exit_code) { should be_zero } + end + end + + describe file('/etc/nginx/conf.mail.d/vhost_autogen.conf') do + it { should be_file } + it { should contain "auth_http localhost/cgi-bin/auth;" } + end + +end diff --git a/spec/system/nginx_proxy_spec.rb b/spec/system/nginx_proxy_spec.rb new file mode 100644 index 0000000..9081eaa --- /dev/null +++ b/spec/system/nginx_proxy_spec.rb @@ -0,0 +1,43 @@ +require 'spec_helper_system' + +describe "nginx::resource::upstream define:" do + context 'should run successfully' do + + pp = " + class { 'nginx': } + nginx::resource::upstream { 'puppet_rack_app': + ensure => present, + members => [ + 'localhost:3000', + 'localhost:3001', + 'localhost:3002', + ], + } + nginx::resource::vhost { 'rack.puppetlabs.com': + ensure => present, + proxy => 'http://puppet_rack_app', + } + " + + context puppet_apply(pp) do + its(:exit_code) { should_not == 1 } + its(:refresh) { should be_nil } + its(:stderr) { should be_empty } + its(:exit_code) { should be_zero } + end + end + + describe file('/etc/nginx/conf.d/puppet_rack_app-upstream.conf') do + it { should be_file } + it { should contain "server localhost:3000" } + it { should contain "server localhost:3001" } + it { should contain "server localhost:3002" } + it { should_not contain "server localhost:3003" } + end + + describe file('/etc/nginx/conf.d/vhost_autogen.conf') do + it { should be_file } + it { should contain "proxy_pass http://puppet_rack_app;" } + end + +end diff --git a/spec/system/nginx_vhost_spec.rb b/spec/system/nginx_vhost_spec.rb new file mode 100644 index 0000000..f1865ed --- /dev/null +++ b/spec/system/nginx_vhost_spec.rb @@ -0,0 +1,27 @@ +require 'spec_helper_system' + +describe "nginx::resource::vhost define:" do + context 'should run successfully' do + + pp = " + class { 'nginx': } + nginx::resource::vhost { 'www.puppetlabs.com': + ensure => present, + www_root => '/var/www/www.puppetlabs.com', + } + " + + context puppet_apply(pp) do + its(:exit_code) { should_not == 1 } + its(:refresh) { should be_nil } + its(:stderr) { should be_empty } + its(:exit_code) { should be_zero } + end + end + + describe file('/etc/nginx/conf.d/vhost_autogen.conf') do + it { should be_file } + it { should contain "www.puppetlabs.com" } + end + +end