From: Jonathan Boyett Date: Wed, 15 Jun 2011 22:08:33 +0000 (-0700) Subject: add tests for table, proto, jump, source, and destination params X-Git-Tag: v0.0.1~43 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=70a3e6ce68d6011b9b40efc8417fdb9e9a1fa7c4;p=puppet-modules%2Fpuppetlabs-firewall.git add tests for table, proto, jump, source, and destination params --- diff --git a/spec/type/iptables_type_spec.rb b/spec/type/iptables_type_spec.rb index aba534f..665c87b 100644 --- a/spec/type/iptables_type_spec.rb +++ b/spec/type/iptables_type_spec.rb @@ -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'