]> review.fuel-infra Code Review - puppet-modules/puppetlabs-firewall.git/commitdiff
Add more system tests: class testing in particular
authorKen Barber <ken@bob.sh>
Sat, 13 Apr 2013 16:27:00 +0000 (17:27 +0100)
committerKen Barber <ken@bob.sh>
Sat, 13 Apr 2013 16:33:55 +0000 (17:33 +0100)
Signed-off-by: Ken Barber <ken@bob.sh>
.gitignore
.nodeset.yml
Gemfile
spec/spec_helper_system.rb
spec/system/basic_spec.rb
spec/system/class_spec.rb [new file with mode: 0644]
spec/system/resource_cmd_spec.rb [new file with mode: 0644]

index 97379c07534b44e153bd26b57c838164697f5030..1ed5eea01a1a59f334e85d2e426a979399236501 100644 (file)
@@ -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
index 0975f506cadd51173e07db5fad8ca31051be3056..767f9cd2f6eaafbfa7bbc1b14a65e3787698e452 100644 (file)
@@ -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 95fa73459fb21e6fe666aaa4f1e89383c76bb8c8..d3ee2661671572dbd8e80a4ba11e7e0f3d15283c 100644 (file)
--- 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']
index 0d1819c6124246c6d0e58e71b0a35d4b9908f9be..9c36272cd24541078bbf61262590262b8ccfaccf 100644 (file)
@@ -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
index e7f8a8557066481f788344b814d93059c3d0a844..5dcfef56faed8f17b6e9b9d92b77a9222b5d4445 100644 (file)
@@ -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 (file)
index 0000000..6dfaa2e
--- /dev/null
@@ -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 (file)
index 0000000..09f7084
--- /dev/null
@@ -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