Skip to content

Commit 8d95179

Browse files
committed
Add more system tests: class testing in particular
Signed-off-by: Ken Barber <[email protected]>
1 parent 315a2c2 commit 8d95179

File tree

7 files changed

+89
-51
lines changed

7 files changed

+89
-51
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ pkg/
22
Gemfile.lock
33
# TODO: Ignore this for now until we decide what to do with it
44
spec/fixtures/manifests/
5+
.ruby-version

Diff for: .nodeset.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,29 @@ default_set: 'centos-64-x64'
33
sets:
44
'centos-59-x64':
55
nodes:
6-
"main":
6+
"main.foo.vm":
77
prefab: 'centos-59-x64'
88
'centos-64-x64':
99
nodes:
10-
"main":
10+
"main.foo.vm":
1111
prefab: 'centos-64-x64'
1212
'fedora-18-x64':
1313
nodes:
14-
"main":
14+
"main.foo.vm":
1515
prefab: 'fedora-18-x64'
1616
'debian-607-x64':
1717
nodes:
18-
"main":
18+
"main.foo.vm":
1919
prefab: 'debian-607-x64'
2020
'debian-70rc1-x64':
2121
nodes:
22-
"main":
22+
"main.foo.vm":
2323
prefab: 'debian-70rc1-x64'
2424
'ubuntu-server-10044-x64':
2525
nodes:
26-
"main":
26+
"main.foo.vm":
2727
prefab: 'ubuntu-server-10044-x64'
2828
'ubuntu-server-12042-x64':
2929
nodes:
30-
"main":
30+
"main.foo.vm":
3131
prefab: 'ubuntu-server-12042-x64'

Diff for: Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ source 'https://rubygems.org'
22

33
group :development, :test do
44
gem 'puppetlabs_spec_helper', :require => false
5-
gem 'rspec-system-puppet', '~>0.3.0'
5+
gem 'rspec-system-puppet', '~>0.3.1'
66
end
77

88
if puppetversion = ENV['PUPPET_GEM_VERSION']

Diff for: spec/spec_helper_system.rb

+25
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,35 @@
33
require 'rspec-system/spec_helper'
44
require 'rspec-system-puppet/helpers'
55

6+
# Just some helpers specific to this module
7+
module LocalHelpers
8+
# This helper flushes all tables on the default machine.
9+
#
10+
# It checks that the flush command returns with no errors.
11+
#
12+
# @return [void]
13+
# @todo Need to optionally do the newer tables
14+
# @example
15+
# it 'should flush tables' do
16+
# iptables_flush_all_tables
17+
# end
18+
def iptables_flush_all_tables
19+
['filter', 'nat', 'mangle', 'raw'].each do |t|
20+
system_run("/sbin/iptables -t #{t} -F") do |r|
21+
r[:exit_code].should == 0
22+
r[:stderr].should == ''
23+
end
24+
end
25+
end
26+
end
27+
628
RSpec.configure do |c|
729
# Project root for the firewall code
830
proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
931

32+
# Import in our local helpers
33+
c.include ::LocalHelpers
34+
1035
# This is where we 'setup' the nodes before running our tests
1136
c.system_setup_block = proc do
1237
# TODO: find a better way of importing this into this namespace

Diff for: spec/system/basic_spec.rb

+7-43
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,13 @@
11
require 'spec_helper_system'
22

3-
# TODO: we probably wanna break this into pieces
3+
# Here we put the more basic fundamental tests, ultra obvious stuff.
44
describe "basic tests:" do
5-
# This helper flushes all tables on the default machine.
6-
#
7-
# It checks that the flush command returns with no errors.
8-
def iptables_flush_all_tables
9-
['filter', 'nat', 'mangle', 'raw'].each do |t|
10-
system_run("/sbin/iptables -t #{t} -F") do |r|
11-
r[:exit_code].should == 0
12-
r[:stderr].should == ''
13-
end
14-
end
15-
end
16-
17-
context 'prelim:' do
18-
it 'make sure we have copied the module across' do
19-
# No point diagnosing any more if the module wasn't copied properly
20-
system_run("ls /etc/puppet/modules/firewall") do |r|
21-
r[:exit_code].should == 0
22-
r[:stdout].should =~ /Modulefile/
23-
r[:stderr].should == ''
24-
end
25-
end
26-
end
27-
28-
context 'puppet resource firewall command:' do
29-
it 'make sure it returns no errors when executed on a clean machine' do
30-
# Except for the absence of iptables, it should run perfectly usually
31-
# most hosts have iptables at least.
32-
puppet_resource('firewall') do |r|
33-
r[:exit_code].should == 0
34-
# don't check stdout, some boxes come with rules, that is normal
35-
r[:stderr].should == ''
36-
end
37-
end
38-
39-
it 'flush iptables and make sure it returns nothing afterwards' do
40-
iptables_flush_all_tables
41-
# No rules, means no output thanks. And no errors as well.
42-
puppet_resource('firewall') do |r|
43-
r[:exit_code].should == 0
44-
r[:stderr].should == ''
45-
r[:stdout].should == "\n"
46-
end
5+
it 'make sure we have copied the module across' do
6+
# No point diagnosing any more if the module wasn't copied properly
7+
system_run("ls /etc/puppet/modules/firewall") do |r|
8+
r[:exit_code].should == 0
9+
r[:stdout].should =~ /Modulefile/
10+
r[:stderr].should == ''
4711
end
4812
end
4913
end

Diff for: spec/system/class_spec.rb

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
require 'spec_helper_system'
2+
3+
describe "firewall class:" do
4+
it "should run without event" do
5+
pp = <<-EOS
6+
class { 'firewall': }
7+
EOS
8+
puppet_apply(pp) do |r|
9+
r[:stderr].should == ''
10+
r[:exit_code].should_not eq(1)
11+
end
12+
end
13+
14+
it "should be idempotent" do
15+
pp = <<-EOS
16+
class { 'firewall': }
17+
EOS
18+
puppet_apply(pp) do |r|
19+
r[:stderr].should == ''
20+
r[:exit_code].should == 0
21+
end
22+
end
23+
end

Diff for: spec/system/resource_cmd_spec.rb

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
require 'spec_helper_system'
2+
3+
# Here we want to test the the resource commands ability to work with different
4+
# existing ruleset scenarios. This will give the parsing capabilities of the
5+
# code a good work out.
6+
describe 'puppet resource firewall command:' do
7+
it 'make sure it returns no errors when executed on a clean machine' do
8+
puppet_resource('firewall') do |r|
9+
r[:exit_code].should == 0
10+
# don't check stdout, some boxes come with rules, that is normal
11+
r[:stderr].should == ''
12+
end
13+
end
14+
15+
it 'flush iptables and make sure it returns nothing afterwards' do
16+
iptables_flush_all_tables
17+
18+
# No rules, means no output thanks. And no errors as well.
19+
puppet_resource('firewall') do |r|
20+
r[:exit_code].should == 0
21+
r[:stderr].should == ''
22+
r[:stdout].should == "\n"
23+
end
24+
end
25+
end

0 commit comments

Comments
 (0)