From f29bf05257bc03e4fbcdc41954a9714f02b945aa Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Mon, 4 Jan 2021 11:51:43 +0000 Subject: [PATCH] Improve tests --- spec/unit/puppet/type/firewall_spec.rb | 8 ++++---- spec/unit/puppet/util/ipcidr_spec.rb | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/spec/unit/puppet/type/firewall_spec.rb b/spec/unit/puppet/type/firewall_spec.rb index 5bd7895..d034b38 100755 --- a/spec/unit/puppet/type/firewall_spec.rb +++ b/spec/unit/puppet/type/firewall_spec.rb @@ -140,7 +140,7 @@ describe firewall do # rubocop:disable RSpec/MultipleDescribes describe 'source error checking' do it 'Invalid address when 256.168.2.0/24' do - expect(-> { resource[:source] = '256.168.2.0/24' }).to raise_error( + expect { resource[:source] = '256.168.2.0/24' }.to raise_error( Puppet::Error, %r{host_to_ip failed} ) end @@ -148,7 +148,7 @@ describe firewall do # rubocop:disable RSpec/MultipleDescribes describe 'destination error checking' do it 'Invalid address when 256.168.2.0/24' do - expect(-> { resource[:destination] = '256.168.2.0/24' }).to raise_error( + expect { resource[:destination] = '256.168.2.0/24' }.to raise_error( Puppet::Error, %r{host_to_ip failed} ) end @@ -156,7 +156,7 @@ describe firewall do # rubocop:disable RSpec/MultipleDescribes describe 'src_range error checking' do it 'Invalid IP when 392.168.1.1-192.168.1.10' do - expect(-> { resource[:src_range] = '392.168.1.1-192.168.1.10' }).to raise_error( + expect { resource[:src_range] = '392.168.1.1-192.168.1.10' }.to raise_error( Puppet::Error, %r{Invalid IP address} ) end @@ -164,7 +164,7 @@ describe firewall do # rubocop:disable RSpec/MultipleDescribes describe 'dst_range error checking' do it 'Invalid IP when 392.168.1.1-192.168.1.10' do - expect(-> { resource[:dst_range] = '392.168.1.1-192.168.1.10' }).to raise_error( + expect { resource[:dst_range] = '392.168.1.1-192.168.1.10' }.to raise_error( Puppet::Error, %r{Invalid IP address} ) end diff --git a/spec/unit/puppet/util/ipcidr_spec.rb b/spec/unit/puppet/util/ipcidr_spec.rb index 8551928..b57fa35 100644 --- a/spec/unit/puppet/util/ipcidr_spec.rb +++ b/spec/unit/puppet/util/ipcidr_spec.rb @@ -56,6 +56,12 @@ describe 'Puppet::Util::IPCidr' do it { expect(host.netmask).to eql '0.0.0.0' } end + describe 'ipv4 invalid address' do + subject(:host) { Puppet::Util::IPCidr.new('256.168.2.0/24') } + + it { expect { host }.to raise_error ArgumentError, %r{256.168.2.0/24} } + end + describe 'ipv6 address' do subject(:host) { ipaddr } -- 2.45.2