From: Ashley Penney Date: Wed, 2 Oct 2013 16:42:56 +0000 (-0400) Subject: Add initial rspec-system tests. X-Git-Tag: 1.4.0~5^2 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=621111ee73d02f3ed64c071972a047c085bac6cf;hp=3e3de6ee924ea75463e9df4ffdb5712c0e145403;p=puppet-modules%2Fpuppetlabs-apt.git Add initial rspec-system tests. This covers: apt::builddep apt::key apt::ppa apt::source apt --- diff --git a/.nodeset.yml b/.nodeset.yml new file mode 100644 index 0000000..ad056fe --- /dev/null +++ b/.nodeset.yml @@ -0,0 +1,19 @@ +--- +default_set: 'ubuntu-server-12042-x64' +sets: + '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' diff --git a/Gemfile b/Gemfile index 881fc90..15bd29d 100644 --- a/Gemfile +++ b/Gemfile @@ -1,9 +1,12 @@ source 'https://rubygems.org' group :development, :test do - gem 'rake', :require => false - gem 'rspec-puppet', :require => false - gem 'puppetlabs_spec_helper', :require => false + gem 'rake', :require => false + gem 'rspec-puppet', :require => false + gem 'puppetlabs_spec_helper', :require => false + gem 'rspec-system', :require => false + gem 'rspec-system-puppet', :require => false + gem 'rspec-system-serverspec', :require => false end if puppetversion = ENV['PUPPET_GEM_VERSION'] @@ -11,5 +14,3 @@ if puppetversion = ENV['PUPPET_GEM_VERSION'] else gem 'puppet', :require => false end - -# vim:ft=ruby diff --git a/Rakefile b/Rakefile index cd3d379..bb60173 100644 --- a/Rakefile +++ b/Rakefile @@ -1 +1,2 @@ require 'puppetlabs_spec_helper/rake_tasks' +require 'rspec-system/rake_task' diff --git a/spec/spec_helper_system.rb b/spec/spec_helper_system.rb new file mode 100644 index 0000000..490a601 --- /dev/null +++ b/spec/spec_helper_system.rb @@ -0,0 +1,30 @@ +require 'rspec-system/spec_helper' +require 'rspec-system-puppet/helpers' +require 'rspec-system-serverspec/helpers' + +include RSpecSystemPuppet::Helpers + +include Serverspec::Helper::RSpecSystem +include Serverspec::Helper::DetectOS + +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 + # May as well update here as this can only run on apt-get machines. + shell('apt-get update') + # Install puppet + puppet_install + + # Install modules and dependencies + puppet_module_install(:source => proj_root, :module_name => 'apt') + shell('puppet module install puppetlabs-stdlib') + end +end diff --git a/spec/system/apt_builddep_spec.rb b/spec/system/apt_builddep_spec.rb new file mode 100644 index 0000000..2fb7487 --- /dev/null +++ b/spec/system/apt_builddep_spec.rb @@ -0,0 +1,37 @@ +require 'spec_helper_system' + +describe 'apt::builddep' do + + context 'reset' do + it 'removes packages' do + shell('apt-get -y remove glusterfs-server') + shell('apt-get -y remove g++') + end + end + + context 'apt::builddep' do + it 'should work with no errors' do + pp = <<-EOS + apt::builddep { 'glusterfs-server': } + EOS + + puppet_apply(pp) do |r| + r.exit_code.should_not == 1 + end + end + + describe 'should install g++ as a dependency' do + describe package('g++') do + it { should be_installed } + end + end + end + + context 'reset' do + it 'removes packages' do + shell('apt-get -y remove glusterfs-server') + shell('apt-get -y remove g++') + end + end + +end diff --git a/spec/system/apt_key_spec.rb b/spec/system/apt_key_spec.rb new file mode 100644 index 0000000..2acc317 --- /dev/null +++ b/spec/system/apt_key_spec.rb @@ -0,0 +1,52 @@ +require 'spec_helper_system' + +describe 'apt::key' do + + context 'reset' do + it 'clean up keys' do + shell('apt-key del 4BD6EC30') + shell('apt-key del D50582E6') + end + end + + context 'apt::key' do + it 'should work with no errors' do + pp = <<-EOS + apt::key { 'puppetlabs': + key => '4BD6EC30', + key_server => 'pgp.mit.edu', + } + + apt::key { 'jenkins': + key => 'D50582E6', + key_source => 'http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key', + } + EOS + + puppet_apply(pp) do |r| + r.exit_code.should_not == 1 + end + end + + describe 'keys should exist' do + it 'finds puppetlabs key' do + shell('apt-key list | grep 4BD6EC30') do |r| + r.exit_code.should be_zero + end + end + it 'finds jenkins key' do + shell('apt-key list | grep D50582E6') do |r| + r.exit_code.should be_zero + end + end + end + end + + context 'reset' do + it 'clean up keys' do + shell('apt-key del 4BD6EC30') + shell('apt-key del D50582E6') + end + end + +end diff --git a/spec/system/apt_ppa_spec.rb b/spec/system/apt_ppa_spec.rb new file mode 100644 index 0000000..8e7090b --- /dev/null +++ b/spec/system/apt_ppa_spec.rb @@ -0,0 +1,38 @@ +require 'spec_helper_system' + +describe 'apt::ppa' do + + context 'reset' do + it 'removes ppa' do + shell('rm /etc/apt/sources.list.d/drizzle-developers-ppa*') + end + end + + context 'apt::ppa' do + it 'should work with no errors' do + pp = <<-EOS + include '::apt' + apt::ppa { 'ppa:drizzle-developers/ppa': } + EOS + + puppet_apply(pp) do |r| + r.exit_code.should_not == 1 + end + end + + describe 'contains the source file' do + it 'contains a drizzle ppa source' do + shell('ls /etc/apt/sources.list.d/drizzle-developers-ppa-*.list') do |r| + r.exit_code.should be_zero + end + end + end + end + + context 'reset' do + it 'removes ppa' do + shell('rm /etc/apt/sources.list.d/drizzle-developers-ppa*') + end + end + +end diff --git a/spec/system/apt_source_spec.rb b/spec/system/apt_source_spec.rb new file mode 100644 index 0000000..8c79f6f --- /dev/null +++ b/spec/system/apt_source_spec.rb @@ -0,0 +1,50 @@ +require 'spec_helper_system' + +describe 'apt::source' do + + context 'reset' do + it 'clean up puppetlabs repo' do + shell('apt-key del 4BD6EC30') + shell('rm /etc/apt/sources.list.d/puppetlabs.list') + end + end + + context 'apt::source' do + it 'should work with no errors' do + pp = <<-EOS + apt::source { 'puppetlabs': + location => 'http://apt.puppetlabs.com', + repos => 'main', + key => '4BD6EC30', + key_server => 'pgp.mit.edu', + } + EOS + + puppet_apply(pp) do |r| + r.exit_code.should_not == 1 + end + end + + describe 'key should exist' do + it 'finds puppetlabs key' do + shell('apt-key list | grep 4BD6EC30') do |r| + r.exit_code.should be_zero + end + end + end + + describe 'source should exist' do + describe file('/etc/apt/sources.list.d/puppetlabs.list') do + it { should be_file } + end + end + end + + context 'reset' do + it 'clean up puppetlabs repo' do + shell('apt-key del 4BD6EC30') + shell('rm /etc/apt/sources.list.d/puppetlabs.list') + end + end + +end diff --git a/spec/system/basic_spec.rb b/spec/system/basic_spec.rb new file mode 100644 index 0000000..a87f908 --- /dev/null +++ b/spec/system/basic_spec.rb @@ -0,0 +1,22 @@ +require 'spec_helper_system' + +describe 'basic tests:' do + # Using puppet_apply as a subject + context puppet_apply 'notice("foo")' do + its(:stdout) { should =~ /foo/ } + its(:stderr) { should be_empty } + its(:exit_code) { should be_zero } + end +end + +describe 'disable selinux:' do + context puppet_apply ' + exec { "setenforce 0": + path => "/bin:/sbin:/usr/bin:/usr/sbin", + onlyif => "which setenforce && getenforce | grep Enforcing", + } + ' do + its(:stderr) { should be_empty } + its(:exit_code) { should_not == 1 } + end +end diff --git a/spec/system/class_spec.rb b/spec/system/class_spec.rb new file mode 100644 index 0000000..7bb6b8d --- /dev/null +++ b/spec/system/class_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper_system' + +describe 'apt class' do + + context 'default parameters' do + # Using puppet_apply as a helper + it 'should work with no errors' do + pp = <<-EOS + class { 'apt': } + EOS + + # Run it twice and test for idempotency + puppet_apply(pp) do |r| + r.exit_code.should_not == 1 + r.refresh + r.exit_code.should be_zero + end + end + end +end