Add initial rspec-system tests.

This covers:

apt::builddep
apt::key
apt::ppa
apt::source
apt
This commit is contained in:
Ashley Penney 2013-10-02 12:42:56 -04:00
parent 3e3de6ee92
commit 621111ee73
10 changed files with 275 additions and 5 deletions

19
.nodeset.yml Normal file
View file

@ -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'

11
Gemfile
View file

@ -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

View file

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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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
spec/system/basic_spec.rb Normal file
View file

@ -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
spec/system/class_spec.rb Normal file
View file

@ -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