From 04b4da95a8f6067bbab3acc9b2dc6542efa9af4b Mon Sep 17 00:00:00 2001 From: Ken Barber Date: Sat, 17 Sep 2011 23:46:35 +0100 Subject: [PATCH] (#9576) Stub iptables type so it will execute on platforms other then linux. This change will help us target other platforms for this type. I've also removed old helpers to align with Puppet core spec_helper. While this might seem more invconvenient it provides more consistency with core Puppet type testing. --- spec/{ => unit}/type/iptables_type_spec.rb | 35 ++++++++++++++-------- 1 file changed, 22 insertions(+), 13 deletions(-) rename spec/{ => unit}/type/iptables_type_spec.rb (83%) diff --git a/spec/type/iptables_type_spec.rb b/spec/unit/type/iptables_type_spec.rb similarity index 83% rename from spec/type/iptables_type_spec.rb rename to spec/unit/type/iptables_type_spec.rb index c345440..cc88010 100644 --- a/spec/type/iptables_type_spec.rb +++ b/spec/unit/type/iptables_type_spec.rb @@ -1,14 +1,28 @@ require 'spec_helper' -describe Puppet::Type.type(:firewall) do +firewall = Puppet::Type.type(:firewall) + +describe firewall do before :each do - setup_resource(:firewall, { + @class = firewall + @provider = stub 'provider' + @provider.stubs(:name).returns(:iptables) + Puppet::Type::Firewall.stubs(:defaultprovider).returns @provider + + @resource = @class.new({ :name => '000 test foo', :chain => 'INPUT', :jump => 'ACCEPT' }) end + # Example on how to test and have the full validation kick in + #lambda { @class.new(:name => "001-test", :chain => chain) }.should_not raise_error + + it 'should have :name be its namevar' do + @class.key_attributes.should == [:name] + end + describe ':name' do it 'should accept a name' do @resource[:name] = '000-test-foo' @@ -42,7 +56,7 @@ describe Puppet::Type.type(:firewall) do end it "should fail when table value is not recognized" do - lambda { @resource[:table] = 'foo' }.should raise_error(Puppet::Error) + lambda { @resource[:table] = 'not valid' }.should raise_error(Puppet::Error) end end @@ -76,12 +90,7 @@ describe Puppet::Type.type(:firewall) do describe addr do 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'] + @resource[addr].should == '127.0.0.1' end end end @@ -152,13 +161,13 @@ describe Puppet::Type.type(:firewall) do describe ':state' do it 'should accept value as a string' do - @resource[:state] = 'INVALID' - @resource[:state].should == ['INVALID'] + @resource[:state] = :INVALID + @resource[:state].should == [:INVALID] end it 'should accept value as an array' do - @resource[:state] = ['INVALID', 'NEW'] - @resource[:state].should == ['INVALID', 'NEW'] + @resource[:state] = [:INVALID, :NEW] + @resource[:state].should == [:INVALID, :NEW] end end -- 2.45.2