]> review.fuel-infra Code Review - puppet-modules/puppetlabs-firewall.git/commitdiff
Update rspec-system tests for rspec-system-puppet 1.5
authorKen Barber <ken@bob.sh>
Wed, 5 Jun 2013 01:52:06 +0000 (02:52 +0100)
committerKen Barber <ken@bob.sh>
Wed, 5 Jun 2013 01:53:33 +0000 (02:53 +0100)
Signed-off-by: Ken Barber <ken@bob.sh>
Gemfile
spec/spec_helper_system.rb
spec/system/basic_spec.rb
spec/system/class_spec.rb
spec/system/params_spec.rb
spec/system/purge_spec.rb
spec/system/resource_cmd_spec.rb
spec/system/stanard_usage_spec.rb [deleted file]
spec/system/standard_usage_spec.rb [new file with mode: 0644]

diff --git a/Gemfile b/Gemfile
index cccc5a87ff393cf87a97504a9d0024eb4936fb3b..3d7afb11a63a4887c9e803ae168b5c413cf18afb 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', '~>1.1', '>=1.1.0'
+  gem 'rspec-system-puppet', '~>1.2', '>=1.2.0'
 end
 
 if puppetversion = ENV['PUPPET_GEM_VERSION']
index 53a4f83c2feb82692ab4e076aefe0bc4d91ca358..cb1763b6d781d2177b56fc89fa0f5116f861eb28 100644 (file)
@@ -17,14 +17,16 @@ module LocalHelpers
    #   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 == ''
+       shell "/sbin/iptables -t #{t} -F" do |r|
+         r.stderr.should be_empty
+         r.exit_code.should be_zero
        end
      end
    end
 end
 
+include RSpecSystemPuppet::Helpers
+
 RSpec.configure do |c|
   # Project root for the firewall code
   proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
@@ -34,12 +36,10 @@ RSpec.configure do |c|
 
   # Import in our local helpers
   c.include ::LocalHelpers
+  c.include RSpecSystemPuppet::Helpers
 
   # 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
-    include RSpecSystemPuppet::Helpers
-
+  c.before :suite do
     # Install puppet
     puppet_install
 
index 5dcfef56faed8f17b6e9b9d92b77a9222b5d4445..2dc917b2ec5ebd3d3f25f6db6bd17d6ded72dcfd 100644 (file)
@@ -4,10 +4,10 @@ require 'spec_helper_system'
 describe "basic tests:" 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 == ''
+    shell 'ls /etc/puppet/modules/firewall' do |r|
+      r.stdout.should =~ /Modulefile/
+      r.stderr.should be_empty
+      r.exit_code.should be_zero
     end
   end
 end
index 6199c2fe2ed4e615e29b715f88163c2f1a427532..20682c84d9e08cf4b96cc46cd25b4ead2b0c8932 100644 (file)
@@ -1,73 +1,53 @@
 require 'spec_helper_system'
 
 describe "firewall class:" do
-  context 'no params:' do
-    let(:pp) do
-      pp = <<-EOS.gsub(/^\s{8}/,'')
-        class { 'firewall': }
-      EOS
-    end
+  it 'should run successfully' do
+    pp = "class { 'firewall': }"
 
-    it "should run without event" do
-      puppet_apply(pp) do |r|
-        r[:stderr].should == ''
-        r[:exit_code].should_not eq(1)
-      end
+    puppet_apply(pp) do |r|
+      r.stderr.should be_empty
+      r.exit_code.should_not == 1
     end
 
-    it "should be idempotent" do
-      puppet_apply(pp) do |r|
-        r[:stderr].should == ''
-        r[:exit_code].should == 0
-      end
+    puppet_apply(pp) do |r|
+      r.stderr.should be_empty
+      r.exit_code.should be_zero
     end
   end
 
-  context 'ensure => stopped:' do
-    let(:pp) do
-      pp = <<-EOS.gsub(/^\s{8}/,'')
-        class { 'firewall':
-          ensure => stopped,
-        }
-      EOS
-    end
+  it 'ensure => stopped:' do
+    pp = <<-EOS
+      class { 'firewall':
+        ensure => stopped,
+      }
+    EOS
 
-    it "should run without event" do
-      puppet_apply(pp) do |r|
-        r[:stderr].should == ''
-        r[:exit_code].should_not eq(1)
-      end
+    puppet_apply(pp) do |r|
+      r.stderr.should be_empty
+      r.exit_code.should_not == 1
     end
 
-    it "should be idempotent" do
-      puppet_apply(pp) do |r|
-        r[:stderr].should == ''
-        r[:exit_code].should == 0
-      end
+    puppet_apply(pp) do |r|
+      r.stderr.should be_empty
+      r.exit_code.should be_zero
     end
   end
 
-  context 'ensure => running:' do
-    let(:pp) do
-      pp = <<-EOS.gsub(/^\s{8}/,'')
-        class { 'firewall':
-          ensure => running,
-        }
-      EOS
-    end
+  it 'ensure => running:' do
+    pp = <<-EOS
+      class { 'firewall':
+        ensure => running,
+      }
+    EOS
 
-    it "should run without event" do
-      puppet_apply(pp) do |r|
-        r[:stderr].should == ''
-        r[:exit_code].should_not eq(1)
-      end
+    puppet_apply(pp) do |r|
+      r.stderr.should be_empty
+      r.exit_code.should_not == 1
     end
 
-    it "should be idempotent" do
-      puppet_apply(pp) do |r|
-        r[:stderr].should == ''
-        r[:exit_code].should == 0
-      end
+    puppet_apply(pp) do |r|
+      r.stderr.should be_empty
+      r.exit_code.should be_zero
     end
   end
 end
index 3e653d4e1572c30a08ad4a1e11f0d1e570e04138..1ffdfae0856aefc7ec9d419b6dec875dd91c0e97 100644 (file)
@@ -1,6 +1,7 @@
 require 'spec_helper_system'
 
 describe "param based tests:" do
+  # Takes a hash and converts it into a firewall resource
   def pp(params)
     name = params.delete('name') || '100 test'
     pm = <<-EOS
@@ -20,7 +21,7 @@ firewall { '#{name}':
   end
 
   it 'test various params' do
-    facts = system_node.facts
+    facts = node.facts
 
     unless (facts['operatingsystem'] == 'CentOS') && \
       facts['operatingsystemrelease'] =~ /^5\./ then
@@ -35,14 +36,14 @@ firewall { '#{name}':
         'log_level' => 'debug',
       })
       puppet_apply(ppm) do |r|
-        r[:stderr].should == ''
-        r[:exit_code].should == 2
+        r.stderr.should be_empty
+        r.exit_code.should == 2
       end
 
       # check idempotency
       puppet_apply(ppm) do |r|
-        r[:stderr].should == ''
-        r[:exit_code].should == 0
+        r.stderr.should be_empty
+        r.exit_code.should be_zero
       end
     end
   end
@@ -57,14 +58,14 @@ firewall { '#{name}':
       'log_level' => 'debug',
     })
     puppet_apply(ppm) do |r|
-      r.stderr.should == ''
+      r.stderr.should be_empty
       r.exit_code.should == 2
     end
 
     # check idempotency
     puppet_apply(ppm) do |r|
-      r.stderr.should == ''
-      r.exit_code.should == 0
+      r.stderr.should be_empty
+      r.exit_code.should be_zero
     end
   end
 
@@ -127,7 +128,7 @@ firewall { '#{name}':
 
     puppet_apply(ppm1) do |r|
       r.stderr.should be_empty
-      r.exit_code.should == 0
+      r.exit_code.should be_zero
     end
   end
 end
index 0c14ee121065adff6a02428646f2d8c5883990f0..9403aedbe61763110c02886bab1c1837ab71432b 100644 (file)
@@ -4,8 +4,8 @@ describe "purge tests:" do
   it 'make sure duplicate existing rules get purged' do
     iptables_flush_all_tables
 
-    system_run('/sbin/iptables -A INPUT -s 1.2.1.2')
-    system_run('/sbin/iptables -A INPUT -s 1.2.1.2')
+    shell('/sbin/iptables -A INPUT -s 1.2.1.2')
+    shell('/sbin/iptables -A INPUT -s 1.2.1.2')
     pp = <<-EOS
 class { 'firewall': }
 resources { 'firewall':
@@ -13,13 +13,13 @@ resources { 'firewall':
 }
     EOS
     puppet_apply(pp) do |r|
-      r[:stderr].should == ''
-      r[:exit_code].should == 2
+      r.stderr.should be_empty
+      r.exit_code.should == 2
     end
 
     system_run('/sbin/iptables-save') do |r|
-      r[:stdout].should_not =~ /1\.2\.1\.2/
-      r[:stderr].should == ''
+      r.stdout.should_not =~ /1\.2\.1\.2/
+      r.stderr.should be_empty
     end
   end
 end
index 091faae981fc4d86e16be10d8048afe1e5ec172f..34ac6b2bf0403a01938e4269513933fd15a01deb 100644 (file)
@@ -6,9 +6,9 @@ require 'spec_helper_system'
 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
+      r.exit_code.should be_zero
       # don't check stdout, some boxes come with rules, that is normal
-      r[:stderr].should == ''
+      r.stderr.should be_empty
     end
   end
 
@@ -17,31 +17,31 @@ describe 'puppet resource firewall command:' do
 
     # 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"
+      r.exit_code.should be_zero
+      r.stderr.should be_empty
+      r.stdout.should == "\n"
     end
   end
-  
+
   it 'accepts rules without comments' do
     iptables_flush_all_tables
-    system_run('/sbin/iptables -A INPUT -j ACCEPT -p tcp --dport 80')
+    shell('/sbin/iptables -A INPUT -j ACCEPT -p tcp --dport 80')
 
     puppet_resource('firewall') do |r|
-      r[:exit_code].should == 0
+      r.exit_code.should be_zero
       # don't check stdout, testing preexisting rules, output is normal
-      r[:stderr].should == ''
+      r.stderr.should be_empty
     end
   end
 
   it 'accepts rules with invalid comments' do
     iptables_flush_all_tables
-    system_run('/sbin/iptables -A INPUT -j ACCEPT -p tcp --dport 80 -m comment --comment "http"')
+    shell('/sbin/iptables -A INPUT -j ACCEPT -p tcp --dport 80 -m comment --comment "http"')
 
     puppet_resource('firewall') do |r|
-      r[:exit_code].should == 0
+      r.exit_code.should be_zero
       # don't check stdout, testing preexisting rules, output is normal
-      r[:stderr].should == ''
+      r.stderr.should be_empty
     end
   end
 end
diff --git a/spec/system/stanard_usage_spec.rb b/spec/system/stanard_usage_spec.rb
deleted file mode 100644 (file)
index fc935f7..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-require 'spec_helper_system'
-
-# Some tests for the standard recommended usage
-describe "standard usage:" do
-  let(:pp) do
-    pp = <<-EOS
-class my_fw::pre {
-  Firewall {
-    require => undef,
-  }
-
-  # Default firewall rules
-  firewall { '000 accept all icmp':
-    proto   => 'icmp',
-    action  => 'accept',
-  }->
-  firewall { '001 accept all to lo interface':
-    proto   => 'all',
-    iniface => 'lo',
-    action  => 'accept',
-  }->
-  firewall { '002 accept related established rules':
-    proto   => 'all',
-    state   => ['RELATED', 'ESTABLISHED'],
-    action  => 'accept',
-  }
-}
-class my_fw::post {
-  firewall { '999 drop all':
-    proto   => 'all',
-    action  => 'drop',
-    before  => undef,
-  }
-}
-resources { "firewall":
-  purge => true
-}
-Firewall {
-  before  => Class['my_fw::post'],
-  require => Class['my_fw::pre'],
-}
-class { ['my_fw::pre', 'my_fw::post']: }
-class { 'firewall': }
-firewall { '500 open up port 22':
-  action => 'accept',
-  proto => 'tcp',
-  dport => 22,
-}
-    EOS
-  end
-
-  it 'make sure it runs without error' do
-    puppet_apply(pp) do |r|
-      r[:stderr].should == ''
-      r[:exit_code].should_not eq(1)
-    end
-  end
-
-  it 'should be idempotent' do
-    puppet_apply(pp) do |r|
-      r[:stderr].should == ''
-      r[:exit_code].should == 0
-    end
-  end
-end
diff --git a/spec/system/standard_usage_spec.rb b/spec/system/standard_usage_spec.rb
new file mode 100644 (file)
index 0000000..ef4dbec
--- /dev/null
@@ -0,0 +1,61 @@
+require 'spec_helper_system'
+
+# Some tests for the standard recommended usage
+describe 'standard usage tests:' do
+  it 'standard 1' do
+    pp = <<-EOS
+      class my_fw::pre {
+        Firewall {
+          require => undef,
+        }
+
+        # Default firewall rules
+        firewall { '000 accept all icmp':
+          proto   => 'icmp',
+          action  => 'accept',
+        }->
+        firewall { '001 accept all to lo interface':
+          proto   => 'all',
+          iniface => 'lo',
+          action  => 'accept',
+        }->
+        firewall { '002 accept related established rules':
+          proto   => 'all',
+          state   => ['RELATED', 'ESTABLISHED'],
+          action  => 'accept',
+        }
+      }
+      class my_fw::post {
+        firewall { '999 drop all':
+          proto   => 'all',
+          action  => 'drop',
+          before  => undef,
+        }
+      }
+      resources { "firewall":
+        purge => true
+      }
+      Firewall {
+        before  => Class['my_fw::post'],
+        require => Class['my_fw::pre'],
+      }
+      class { ['my_fw::pre', 'my_fw::post']: }
+      class { 'firewall': }
+      firewall { '500 open up port 22':
+        action => 'accept',
+        proto => 'tcp',
+        dport => 22,
+      }
+    EOS
+
+    puppet_apply(pp) do |r|
+      r.stderr.should be_empty
+      r.exit_code.should_not == 1
+    end
+
+    puppet_apply(pp) do |r|
+      r.stderr.should be_empty
+      r.exit_code.should be_zero
+    end
+  end
+end