From: Ken Barber Date: Sat, 13 Apr 2013 16:27:00 +0000 (+0100) Subject: Add more system tests: class testing in particular X-Git-Tag: 0.3.0~11^2 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=8d951790a8ef249730691a8b4b7fd376b8d1b73e;p=puppet-modules%2Fpuppetlabs-firewall.git Add more system tests: class testing in particular Signed-off-by: Ken Barber --- diff --git a/.gitignore b/.gitignore index 97379c0..1ed5eea 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ pkg/ Gemfile.lock # TODO: Ignore this for now until we decide what to do with it spec/fixtures/manifests/ +.ruby-version diff --git a/.nodeset.yml b/.nodeset.yml index 0975f50..767f9cd 100644 --- a/.nodeset.yml +++ b/.nodeset.yml @@ -3,29 +3,29 @@ default_set: 'centos-64-x64' sets: 'centos-59-x64': nodes: - "main": + "main.foo.vm": prefab: 'centos-59-x64' 'centos-64-x64': nodes: - "main": + "main.foo.vm": prefab: 'centos-64-x64' 'fedora-18-x64': nodes: - "main": + "main.foo.vm": prefab: 'fedora-18-x64' 'debian-607-x64': nodes: - "main": + "main.foo.vm": prefab: 'debian-607-x64' 'debian-70rc1-x64': nodes: - "main": + "main.foo.vm": prefab: 'debian-70rc1-x64' 'ubuntu-server-10044-x64': nodes: - "main": + "main.foo.vm": prefab: 'ubuntu-server-10044-x64' 'ubuntu-server-12042-x64': nodes: - "main": + "main.foo.vm": prefab: 'ubuntu-server-12042-x64' diff --git a/Gemfile b/Gemfile index 95fa734..d3ee266 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,7 @@ source 'https://rubygems.org' group :development, :test do gem 'puppetlabs_spec_helper', :require => false - gem 'rspec-system-puppet', '~>0.3.0' + gem 'rspec-system-puppet', '~>0.3.1' end if puppetversion = ENV['PUPPET_GEM_VERSION'] diff --git a/spec/spec_helper_system.rb b/spec/spec_helper_system.rb index 0d1819c..9c36272 100644 --- a/spec/spec_helper_system.rb +++ b/spec/spec_helper_system.rb @@ -3,10 +3,35 @@ require 'rspec-system/spec_helper' require 'rspec-system-puppet/helpers' +# Just some helpers specific to this module +module LocalHelpers + # This helper flushes all tables on the default machine. + # + # It checks that the flush command returns with no errors. + # + # @return [void] + # @todo Need to optionally do the newer tables + # @example + # it 'should flush tables' do + # iptables_flush_all_tables + # end + def iptables_flush_all_tables + ['filter', 'nat', 'mangle', 'raw'].each do |t| + system_run("/sbin/iptables -t #{t} -F") do |r| + r[:exit_code].should == 0 + r[:stderr].should == '' + end + end + end +end + RSpec.configure do |c| # Project root for the firewall code proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) + # Import in our local helpers + c.include ::LocalHelpers + # This is where we 'setup' the nodes before running our tests c.system_setup_block = proc do # TODO: find a better way of importing this into this namespace diff --git a/spec/system/basic_spec.rb b/spec/system/basic_spec.rb index e7f8a85..5dcfef5 100644 --- a/spec/system/basic_spec.rb +++ b/spec/system/basic_spec.rb @@ -1,49 +1,13 @@ require 'spec_helper_system' -# TODO: we probably wanna break this into pieces +# Here we put the more basic fundamental tests, ultra obvious stuff. describe "basic tests:" do - # This helper flushes all tables on the default machine. - # - # It checks that the flush command returns with no errors. - def iptables_flush_all_tables - ['filter', 'nat', 'mangle', 'raw'].each do |t| - system_run("/sbin/iptables -t #{t} -F") do |r| - r[:exit_code].should == 0 - r[:stderr].should == '' - end - end - end - - context 'prelim:' do - it 'make sure we have copied the module across' do - # No point diagnosing any more if the module wasn't copied properly - system_run("ls /etc/puppet/modules/firewall") do |r| - r[:exit_code].should == 0 - r[:stdout].should =~ /Modulefile/ - r[:stderr].should == '' - end - end - end - - context 'puppet resource firewall command:' do - it 'make sure it returns no errors when executed on a clean machine' do - # Except for the absence of iptables, it should run perfectly usually - # most hosts have iptables at least. - puppet_resource('firewall') do |r| - r[:exit_code].should == 0 - # don't check stdout, some boxes come with rules, that is normal - r[:stderr].should == '' - end - end - - it 'flush iptables and make sure it returns nothing afterwards' do - iptables_flush_all_tables - # No rules, means no output thanks. And no errors as well. - puppet_resource('firewall') do |r| - r[:exit_code].should == 0 - r[:stderr].should == '' - r[:stdout].should == "\n" - end + it 'make sure we have copied the module across' do + # No point diagnosing any more if the module wasn't copied properly + system_run("ls /etc/puppet/modules/firewall") do |r| + r[:exit_code].should == 0 + r[:stdout].should =~ /Modulefile/ + r[:stderr].should == '' end end end diff --git a/spec/system/class_spec.rb b/spec/system/class_spec.rb new file mode 100644 index 0000000..6dfaa2e --- /dev/null +++ b/spec/system/class_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper_system' + +describe "firewall class:" do + it "should run without event" do + pp = <<-EOS + class { 'firewall': } + EOS + puppet_apply(pp) do |r| + r[:stderr].should == '' + r[:exit_code].should_not eq(1) + end + end + + it "should be idempotent" do + pp = <<-EOS + class { 'firewall': } + EOS + puppet_apply(pp) do |r| + r[:stderr].should == '' + r[:exit_code].should == 0 + end + end +end diff --git a/spec/system/resource_cmd_spec.rb b/spec/system/resource_cmd_spec.rb new file mode 100644 index 0000000..09f7084 --- /dev/null +++ b/spec/system/resource_cmd_spec.rb @@ -0,0 +1,25 @@ +require 'spec_helper_system' + +# Here we want to test the the resource commands ability to work with different +# existing ruleset scenarios. This will give the parsing capabilities of the +# code a good work out. +describe 'puppet resource firewall command:' do + it 'make sure it returns no errors when executed on a clean machine' do + puppet_resource('firewall') do |r| + r[:exit_code].should == 0 + # don't check stdout, some boxes come with rules, that is normal + r[:stderr].should == '' + end + end + + it 'flush iptables and make sure it returns nothing afterwards' do + iptables_flush_all_tables + + # No rules, means no output thanks. And no errors as well. + puppet_resource('firewall') do |r| + r[:exit_code].should == 0 + r[:stderr].should == '' + r[:stdout].should == "\n" + end + end +end