]> review.fuel-infra Code Review - puppet-modules/puppetlabs-firewall.git/commitdiff
add tests for table, proto, jump, source, and destination params
authorJonathan Boyett <jonathan@failingservers.com>
Wed, 15 Jun 2011 22:08:33 +0000 (15:08 -0700)
committerJonathan Boyett <jonathan@failingservers.com>
Wed, 15 Jun 2011 22:08:33 +0000 (15:08 -0700)
spec/type/iptables_type_spec.rb

index aba534f8fbd38e5f5175e68cb6a46ea11311bc5a..665c87bdd2c7322653e9d1cebcceac9c4ea84aba 100644 (file)
@@ -16,8 +16,7 @@ describe Puppet::Type.type(:firewall) do
     end
 
     it 'should not accept a name with non-ASCII chars' do
-      @resource[:name] = '%*#^(#$'
-      @resource[:name].should raise_error(Puppet::Type::Firewall)
+      lambda { @resource[:name] = '%*#^(#$' }.should raise_error(Puppet::Error)
     end
   end
 
@@ -28,6 +27,10 @@ describe Puppet::Type.type(:firewall) do
         @resource[:chain].should == chain
       end
     end
+
+    it 'should fail when the chain value is not recognized' do
+      lambda { @resource[:chain] = 'foo' }.should raise_error(Puppet::Error)
+    end
   end
 
   describe ':table' do
@@ -37,9 +40,53 @@ describe Puppet::Type.type(:firewall) do
         @resource[:table].should == table
       end
     end
+
+    it "should fail when table value is not recognized" do
+      lambda { @resource[:table] = 'foo' }.should raise_error(Puppet::Error)
+    end
+  end
+
+  describe ':proto' do
+    [:tcp, :udp, :icmp, :esp, :ah, :vrrp, :igmp, :all].each do |proto|
+      it "should accept proto value #{proto}" do
+        @resource[:proto] = proto
+        @resource[:proto].should == proto
+      end
+    end
+
+    it "should fail when proto value is not recognized" do
+      lambda { @resource[:proto] = 'foo' }.should raise_error(Puppet::Error)
+    end
+  end
+
+  describe ':jump' do
+    [:ACCEPT, :DROP, :QUEUE, :RETURN, :REJECT, :DNAT, :SNAT, :LOG, :MASQUERADE, :REDIRECT].each do |jump|
+      it "should accept jump value #{jump}" do
+        @resource[:jump] = jump
+        @resource[:jump].should == jump
+      end
+    end
+
+    it "should fail when jump value is not recognized" do
+      lambda { @resource[:proto] = 'jump' }.should raise_error(Puppet::Error)
+    end
+  end
+
+  describe ':source/:destination' do
+    [:source, :destination].each do |addr|
+      it "should accept a #{addr} as a string" do
+        @resource[addr] = '127.0.0.1'
+        @resource[addr].should == ['127.0.0.1']
+      end
+
+      it "should accept a #{addr} as an array" do
+        @resource[addr] = ['127.0.0.1', '4.2.2.2']
+        @resource[addr].should == ['127.0.0.1', '4.2.2.2']
+      end
+    end
   end
 
-  describe ':dport/sport' do
+  describe ':dport/:sport' do
     [:dport, :sport].each do |port|
       it "should accept a #{port} as string" do
         @resource[port] = '22'