Browse Source

Add initial rspec-system tests.

This covers:

apt::builddep
apt::key
apt::ppa
apt::source
apt
Ashley Penney 10 years ago
parent
commit
621111ee73

+ 19 - 0
.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'

+ 6 - 5
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

+ 1 - 0
Rakefile

@@ -1 +1,2 @@
 require 'puppetlabs_spec_helper/rake_tasks'
+require 'rspec-system/rake_task'

+ 30 - 0
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

+ 37 - 0
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

+ 52 - 0
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

+ 38 - 0
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

+ 50 - 0
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

+ 22 - 0
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

+ 20 - 0
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