diff --git a/spec/classes/network_carp_spec.rb b/spec/classes/network_carp_spec.rb index 3881b87..57c7e6b 100644 --- a/spec/classes/network_carp_spec.rb +++ b/spec/classes/network_carp_spec.rb @@ -4,23 +4,21 @@ describe 'bsd::network::carp' do on_supported_os.each do |os, facts| let(:facts) { facts } context "on #{os}" do - context 'with allowed' do - let(:params) { {:allowed => true} } + let(:params) { { allowed: true } } it do - should contain_class('bsd::network::carp') - should contain_sysctl('net.inet.carp.allow').with_value('1') + is_expected.to contain_class('bsd::network::carp') + is_expected.to contain_sysctl('net.inet.carp.allow').with_value('1') end end context 'with preempt' do - let(:params) { {:preempt => true} } + let(:params) { { preempt: true } } it do - should contain_class('bsd::network::carp') - should contain_sysctl('net.inet.carp.preempt').with_value('1') + is_expected.to contain_class('bsd::network::carp') + is_expected.to contain_sysctl('net.inet.carp.preempt').with_value('1') end end - end end end diff --git a/spec/classes/network_gre_spec.rb b/spec/classes/network_gre_spec.rb index 1eaeae0..305ca3a 100644 --- a/spec/classes/network_gre_spec.rb +++ b/spec/classes/network_gre_spec.rb @@ -4,49 +4,53 @@ describe 'bsd::network::gre' do on_supported_os.each do |os, facts| let(:facts) { facts } context "on #{os}" do - context 'with allowed' do - let(:params) {{ - :allowed => true, - :wccp => false, - :mobileip => false, - }} + let(:params) do + { + allowed: true, + wccp: false, + mobileip: false + } + end it do - should contain_class('bsd::network::gre') - should contain_sysctl('net.inet.gre.allow').with_value('1') - should contain_sysctl('net.inet.gre.wccp').with_value('0') - should contain_sysctl('net.inet.mobileip.allow').with_value('0') + is_expected.to contain_class('bsd::network::gre') + is_expected.to contain_sysctl('net.inet.gre.allow').with_value('1') + is_expected.to contain_sysctl('net.inet.gre.wccp').with_value('0') + is_expected.to contain_sysctl('net.inet.mobileip.allow').with_value('0') end end context 'with wccp' do - let(:params) {{ - :allowed => false, - :wccp => true, - :mobileip => false, - }} + let(:params) do + { + allowed: false, + wccp: true, + mobileip: false + } + end it do - should contain_class('bsd::network::gre') - should contain_sysctl('net.inet.gre.allow').with_value('0') - should contain_sysctl('net.inet.gre.wccp').with_value('1') - should contain_sysctl('net.inet.mobileip.allow').with_value('0') + is_expected.to contain_class('bsd::network::gre') + is_expected.to contain_sysctl('net.inet.gre.allow').with_value('0') + is_expected.to contain_sysctl('net.inet.gre.wccp').with_value('1') + is_expected.to contain_sysctl('net.inet.mobileip.allow').with_value('0') end end context 'with mobileip' do - let(:params) {{ - :allowed => false, - :wccp => false, - :mobileip => true, - }} + let(:params) do + { + allowed: false, + wccp: false, + mobileip: true + } + end it do - should contain_class('bsd::network::gre') - should contain_sysctl('net.inet.gre.allow').with_value('0') - should contain_sysctl('net.inet.gre.wccp').with_value('0') - should contain_sysctl('net.inet.mobileip.allow').with_value('1') + is_expected.to contain_class('bsd::network::gre') + is_expected.to contain_sysctl('net.inet.gre.allow').with_value('0') + is_expected.to contain_sysctl('net.inet.gre.wccp').with_value('0') + is_expected.to contain_sysctl('net.inet.mobileip.allow').with_value('1') end end - end end end diff --git a/spec/classes/network_spec.rb b/spec/classes/network_spec.rb index 17078a8..24bc8db 100644 --- a/spec/classes/network_spec.rb +++ b/spec/classes/network_spec.rb @@ -5,52 +5,48 @@ describe 'bsd::network' do context "on #{os}" do let(:facts) { facts } context 'with default params' do - it { - should contain_class('bsd::network') - should contain_sysctl('net.inet6.ip6.forwarding').with_value('0') - should contain_sysctl('net.inet.ip.forwarding').with_value('0') - } + it do + is_expected.to contain_class('bsd::network') + is_expected.to contain_sysctl('net.inet6.ip6.forwarding').with_value('0') + is_expected.to contain_sysctl('net.inet.ip.forwarding').with_value('0') + end end context 'with forwarding enabled' do - let(:params) { {:v4forwarding => true, :v6forwarding => true} } - it { - should contain_class('bsd::network') - should contain_sysctl('net.inet6.ip6.forwarding').with_value('1') - should contain_sysctl('net.inet.ip.forwarding').with_value('1') - } + let(:params) { { v4forwarding: true, v6forwarding: true } } + it do + is_expected.to contain_class('bsd::network') + is_expected.to contain_sysctl('net.inet6.ip6.forwarding').with_value('1') + is_expected.to contain_sysctl('net.inet.ip.forwarding').with_value('1') + end case facts[:osfamily] when 'FreeBSD' - it { - should contain_shellvar('gateway_enable').with_value('YES') - should contain_shellvar('ipv6_gateway_enable').with_value('YES') - } + it do + is_expected.to contain_shellvar('gateway_enable').with_value('YES') + is_expected.to contain_shellvar('ipv6_gateway_enable').with_value('YES') + end end - end context 'with gateways set' do - let(:params) { {:v4gateway => '123.123.123.123', :v6gateway => '123::'} } - it { - should contain_class('bsd::network') - } + let(:params) { { v4gateway: '123.123.123.123', v6gateway: '123::' } } + it do + is_expected.to contain_class('bsd::network') + end case facts[:osfamily] when 'FreeBSD' - it { - should contain_shellvar('defaultrouter').with_value('123.123.123.123') - should contain_shellvar('ipv6_defaultrouter').with_value('123::') - } + it do + is_expected.to contain_shellvar('defaultrouter').with_value('123.123.123.123') + is_expected.to contain_shellvar('ipv6_defaultrouter').with_value('123::') + end when 'OpenBSD' - it { - should contain_file('/etc/mygate') - } + it do + is_expected.to contain_file('/etc/mygate') + end end - end - end end end - diff --git a/spec/defines/bsd_network_interface_bridge_spec.rb b/spec/defines/bsd_network_interface_bridge_spec.rb index 02d4de2..fbe49be 100644 --- a/spec/defines/bsd_network_interface_bridge_spec.rb +++ b/spec/defines/bsd_network_interface_bridge_spec.rb @@ -1,64 +1,64 @@ require 'spec_helper' -describe "bsd::network::interface::bridge" do - context "on OpenBSD" do - let(:facts) { {:kernel => 'OpenBSD'} } +describe 'bsd::network::interface::bridge' do + context 'on OpenBSD' do + let(:facts) { { kernel: 'OpenBSD' } } let(:title) { 'bridge0' } - context " a minimal example" do - let(:params) { + context ' a minimal example' do + let(:params) do { - :interface => ['em0', 'em1'] + interface: %w(em0 em1) } - } - it do - should contain_bsd__network__interface__bridge('bridge0') - should contain_bsd__network__interface('bridge0').with_parents(['em0', 'em1']) - should contain_bsd_interface('bridge0') end it do - should contain_file('/etc/hostname.bridge0').with_content(/add em0\nadd em1\nup\n/) + is_expected.to contain_bsd__network__interface__bridge('bridge0') + is_expected.to contain_bsd__network__interface('bridge0').with_parents(%w(em0 em1)) + is_expected.to contain_bsd_interface('bridge0') + end + it do + is_expected.to contain_file('/etc/hostname.bridge0').with_content(%r{add em0\nadd em1\nup\n}) end end - context "a medium example" do - let(:params) { + context 'a medium example' do + let(:params) do { - :interface => ['em0', 'em1'], - :description => "TestNet" + interface: %w(em0 em1), + description: 'TestNet' } - } - it do - should contain_bsd__network__interface('bridge0').with_parents(['em0', 'em1']) end it do - should contain_file('/etc/hostname.bridge0').with_content(/description "TestNet"\nadd em0\nadd em1\nup\n/) + is_expected.to contain_bsd__network__interface('bridge0').with_parents(%w(em0 em1)) + end + it do + is_expected.to contain_file('/etc/hostname.bridge0').with_content(%r{description "TestNet"\nadd em0\nadd em1\nup\n}) end end - context " a bit more extensive example with values set" do - let(:params) { + context ' a bit more extensive example with values set' do + let(:params) do { - :interface => ['em0', 'em1'], - :raw_values => '!route add -net 10.10.10.0/24 10.0.0.254', + interface: %w(em0 em1), + raw_values: '!route add -net 10.10.10.0/24 10.0.0.254' } - } - it do - should contain_bsd__network__interface('bridge0').with_parents(['em0', 'em1']) end it do - should contain_file('/etc/hostname.bridge0').with_content(/add em0\nadd em1\n!route add -net 10.10.10.0\/24 10.0.0.254\nup\n/) + is_expected.to contain_bsd__network__interface('bridge0').with_parents(%w(em0 em1)) + end + it do + is_expected.to contain_file('/etc/hostname.bridge0').with_content(/add em0\nadd em1\n!route add -net 10.10.10.0\/24 10.0.0.254\nup\n/) end end end - context "when a bad name is used" do - let(:facts) { {:kernel => 'OpenBSD'} } + context 'when a bad name is used' do + let(:facts) { { kernel: 'OpenBSD' } } let(:title) { 'notcorrect0' } - let(:params) { {:interface => ['em0', 'em1'], :description => "TestNet"} } + let(:params) { { interface: %w(em0 em1), description: 'TestNet' } } it do - expect { - should contain_bsd__network__interface__bridge('notcorrect0') - }.to raise_error(Puppet::Error, /does not match/) + expect do + is_expected.to contain_bsd__network__interface__bridge('notcorrect0') + end.to raise_error(Puppet::Error, %r{does not match}) end end end diff --git a/spec/defines/bsd_network_interface_carp_spec.rb b/spec/defines/bsd_network_interface_carp_spec.rb index 2392be8..c3b0ce2 100644 --- a/spec/defines/bsd_network_interface_carp_spec.rb +++ b/spec/defines/bsd_network_interface_carp_spec.rb @@ -1,107 +1,107 @@ require 'spec_helper' -describe "bsd::network::interface::carp" do - context "on OpenBSD" do - let(:facts) { {:kernel => 'OpenBSD'} } +describe 'bsd::network::interface::carp' do + context 'on OpenBSD' do + let(:facts) { { kernel: 'OpenBSD' } } let(:title) { 'carp0' } - context " a minimal example" do - let(:params) { + context ' a minimal example' do + let(:params) do { - :id => '1', - :device => 'em0', - :address => ['10.0.0.1/24'], - :advbase => '1', - :advskew => '0', - :pass => 'TopSecret', + id: '1', + device: 'em0', + address: ['10.0.0.1/24'], + advbase: '1', + advskew: '0', + pass: 'TopSecret' } - } - it do - should contain_bsd__network__interface__carp('carp0') - should contain_bsd__network__interface('carp0').with_parents(['em0']) - should contain_bsd_interface('carp0') end it do - should contain_file('/etc/hostname.carp0').with_content(/vhid 1 pass TopSecret carpdev em0 advbase 1 advskew 0\ninet 10.0.0.1 255.255.255.0 NONE\nup\n/) + is_expected.to contain_bsd__network__interface__carp('carp0') + is_expected.to contain_bsd__network__interface('carp0').with_parents(['em0']) + is_expected.to contain_bsd_interface('carp0') + end + it do + is_expected.to contain_file('/etc/hostname.carp0').with_content(%r{vhid 1 pass TopSecret carpdev em0 advbase 1 advskew 0\ninet 10.0.0.1 255.255.255.0 NONE\nup\n}) end end - context " a bit more extensive example with values set" do - let(:params) { + context ' a bit more extensive example with values set' do + let(:params) do { - :id => '1', - :device => 'em0', - :address => ['10.0.0.1/24'], - :advbase => '1', - :advskew => '0', - :pass => 'TopSecret', - :raw_values => '!route add -net 10.10.10.0/24 10.0.0.254', + id: '1', + device: 'em0', + address: ['10.0.0.1/24'], + advbase: '1', + advskew: '0', + pass: 'TopSecret', + raw_values: '!route add -net 10.10.10.0/24 10.0.0.254' } - } - it do - should contain_bsd__network__interface('carp0').with_parents(['em0']) end it do - should contain_file('/etc/hostname.carp0').with_content(/vhid 1 pass TopSecret carpdev em0 advbase 1 advskew 0\ninet 10.0.0.1 255.255.255.0 NONE\n!route add -net 10.10.10.0\/24 10.0.0.254\nup\n/) + is_expected.to contain_bsd__network__interface('carp0').with_parents(['em0']) + end + it do + is_expected.to contain_file('/etc/hostname.carp0').with_content(/vhid 1 pass TopSecret carpdev em0 advbase 1 advskew 0\ninet 10.0.0.1 255.255.255.0 NONE\n!route add -net 10.10.10.0\/24 10.0.0.254\nup\n/) end end - context " a bit more extensive example with multiple values set" do - let(:params) { + context ' a bit more extensive example with multiple values set' do + let(:params) do { - :id => '1', - :device => 'em0', - :address => ['10.0.0.1/24'], - :advbase => '1', - :advskew => '0', - :pass => 'TopSecret', - :raw_values => [ '!route add -net 10.10.10.0/24 10.0.0.254', '!route add -net 10.20.10.0/24 10.0.0.254', ], + id: '1', + device: 'em0', + address: ['10.0.0.1/24'], + advbase: '1', + advskew: '0', + pass: 'TopSecret', + raw_values: ['!route add -net 10.10.10.0/24 10.0.0.254', '!route add -net 10.20.10.0/24 10.0.0.254'] } - } - it do - should contain_bsd__network__interface('carp0').with_parents(['em0']) end it do - should contain_file('/etc/hostname.carp0').with_content(/vhid 1 pass TopSecret carpdev em0 advbase 1 advskew 0\ninet 10.0.0.1 255.255.255.0 NONE\n!route add -net 10.10.10.0\/24 10.0.0.254\n!route add -net 10.20.10.0\/24 10.0.0.254\nup\n/) + is_expected.to contain_bsd__network__interface('carp0').with_parents(['em0']) + end + it do + is_expected.to contain_file('/etc/hostname.carp0').with_content(/vhid 1 pass TopSecret carpdev em0 advbase 1 advskew 0\ninet 10.0.0.1 255.255.255.0 NONE\n!route add -net 10.10.10.0\/24 10.0.0.254\n!route add -net 10.20.10.0\/24 10.0.0.254\nup\n/) end end - context " a bit more extensive example with multiple addresses" do - let(:params) { + context ' a bit more extensive example with multiple addresses' do + let(:params) do { - :id => '1', - :device => 'em0', - :address => [ '10.0.0.1/24', '10.0.0.2/32', '10.0.0.3/32' ], - :advbase => '1', - :advskew => '0', - :pass => 'TopSecret', + id: '1', + device: 'em0', + address: ['10.0.0.1/24', '10.0.0.2/32', '10.0.0.3/32'], + advbase: '1', + advskew: '0', + pass: 'TopSecret' } - } - it do - should contain_bsd__network__interface('carp0').with_parents(['em0']) end it do - should contain_file('/etc/hostname.carp0').with_content(/vhid 1 pass TopSecret carpdev em0 advbase 1 advskew 0\ninet 10.0.0.1 255.255.255.0 NONE\ninet alias 10.0.0.2 255.255.255.255 NONE\ninet alias 10.0.0.3 255.255.255.255 NONE\nup\n/) + is_expected.to contain_bsd__network__interface('carp0').with_parents(['em0']) + end + it do + is_expected.to contain_file('/etc/hostname.carp0').with_content(%r{vhid 1 pass TopSecret carpdev em0 advbase 1 advskew 0\ninet 10.0.0.1 255.255.255.0 NONE\ninet alias 10.0.0.2 255.255.255.255 NONE\ninet alias 10.0.0.3 255.255.255.255 NONE\nup\n}) end end end - context "when a bad name is used" do - let(:facts) { {:kernel => 'OpenBSD'} } + context 'when a bad name is used' do + let(:facts) { { kernel: 'OpenBSD' } } let(:title) { 'notcorrect0' } - let(:params) { + let(:params) do { - :id => '1', - :device => 'em0', - :address => ['10.0.0.1/24'], - :advbase => '1', - :advskew => '0', - :pass => 'TopSecret', + id: '1', + device: 'em0', + address: ['10.0.0.1/24'], + advbase: '1', + advskew: '0', + pass: 'TopSecret' } - } + end it do - expect { - should contain_bsd__network__interface__carp('notcorrect0') - }.to raise_error(Puppet::Error, /does not match/) + expect do + is_expected.to contain_bsd__network__interface__carp('notcorrect0') + end.to raise_error(Puppet::Error, %r{does not match}) end end end diff --git a/spec/defines/bsd_network_interface_pfsync_spec.rb b/spec/defines/bsd_network_interface_pfsync_spec.rb index c9445ae..7775546 100644 --- a/spec/defines/bsd_network_interface_pfsync_spec.rb +++ b/spec/defines/bsd_network_interface_pfsync_spec.rb @@ -1,82 +1,90 @@ require 'spec_helper' -describe "bsd::network::interface::pfsync" do - context "on OpenBSD" do - let(:facts) { {:kernel => 'OpenBSD'} } +describe 'bsd::network::interface::pfsync' do + context 'on OpenBSD' do + let(:facts) { { kernel: 'OpenBSD' } } let(:title) { 'pfsync0' } - context "an example with all default values" do + context 'an example with all default values' do it do - should contain_bsd__network__interface__pfsync('pfsync0') - should contain_bsd__network__interface('pfsync0') - should contain_bsd_interface('pfsync0') + is_expected.to contain_bsd__network__interface__pfsync('pfsync0') + is_expected.to contain_bsd__network__interface('pfsync0') + is_expected.to contain_bsd_interface('pfsync0') end it do - should contain_file('/etc/hostname.pfsync0').with_content(/-syncdev -syncpeer maxupd 128 -defer\nup\n/) + is_expected.to contain_file('/etc/hostname.pfsync0').with_content(%r{-syncdev -syncpeer maxupd 128 -defer\nup\n}) end end - context "a minimal example" do - let(:params) { {:syncdev => 'em0'} } + context 'a minimal example' do + let(:params) { { syncdev: 'em0' } } it do - should contain_bsd__network__interface('pfsync0').with_parents(['em0']) + is_expected.to contain_bsd__network__interface('pfsync0').with_parents(['em0']) end it do - should contain_file('/etc/hostname.pfsync0').with_content(/syncdev em0 -syncpeer maxupd 128 -defer\nup\n/) + is_expected.to contain_file('/etc/hostname.pfsync0').with_content(%r{syncdev em0 -syncpeer maxupd 128 -defer\nup\n}) end end - context "a medium example" do - let(:params) { {:syncdev => 'em0', :description => "TestNet"} } + context 'a medium example' do + let(:params) { { syncdev: 'em0', description: 'TestNet' } } it do - should contain_bsd__network__interface('pfsync0').with_parents(['em0']) + is_expected.to contain_bsd__network__interface('pfsync0').with_parents(['em0']) end it do - should contain_file('/etc/hostname.pfsync0').with_content(/description \"TestNet\"\nsyncdev em0 -syncpeer maxupd 128 -defer\nup\n/) + is_expected.to contain_file('/etc/hostname.pfsync0').with_content(%r{description \"TestNet\"\nsyncdev em0 -syncpeer maxupd 128 -defer\nup\n}) end end - context "an example with syncpeer" do - let(:params) { { - :syncdev => 'em0', - :syncpeer => '10.0.0.222', - } } - it do - should contain_bsd__network__interface('pfsync0').with_parents(['em0']) + context 'an example with syncpeer' do + let(:params) do + { + syncdev: 'em0', + syncpeer: '10.0.0.222' + } end it do - should contain_file('/etc/hostname.pfsync0').with_content( - /syncdev em0 syncpeer 10.0.0.222 maxupd 128 -defer\nup\n/) + is_expected.to contain_bsd__network__interface('pfsync0').with_parents(['em0']) + end + it do + is_expected.to contain_file('/etc/hostname.pfsync0').with_content( + %r{syncdev em0 syncpeer 10.0.0.222 maxupd 128 -defer\nup\n} + ) end end - context "an example with non-default maxupd and defer" do - let(:params) { { - :syncdev => 'em0', - :syncpeer => '10.0.0.222', - :maxupd => '156', - :defer => true, - } } - it do - should contain_bsd__network__interface('pfsync0').with_parents(['em0']) + context 'an example with non-default maxupd and defer' do + let(:params) do + { + syncdev: 'em0', + syncpeer: '10.0.0.222', + maxupd: '156', + defer: true + } end it do - should contain_file('/etc/hostname.pfsync0').with_content( - /syncdev em0 syncpeer 10.0.0.222 maxupd 156 defer\nup\n/) + is_expected.to contain_bsd__network__interface('pfsync0').with_parents(['em0']) + end + it do + is_expected.to contain_file('/etc/hostname.pfsync0').with_content( + %r{syncdev em0 syncpeer 10.0.0.222 maxupd 156 defer\nup\n} + ) end end end - context "when a bad name is used" do - let(:facts) { {:kernel => 'OpenBSD'} } + context 'when a bad name is used' do + let(:facts) { { kernel: 'OpenBSD' } } let(:title) { 'notcorrect0' } - let(:params) { { - :syncdev => 'em0', - :description => "TestNet" - } } + let(:params) do + { + syncdev: 'em0', + description: 'TestNet' + } + end it do - expect { - should contain_bsd__network__interface__pfsync('notcorrect0') - }.to raise_error(Puppet::Error, /does not match/) + expect do + is_expected.to contain_bsd__network__interface__pfsync('notcorrect0') + end.to raise_error(Puppet::Error, %r{does not match}) end end end diff --git a/spec/defines/bsd_network_interface_spec.rb b/spec/defines/bsd_network_interface_spec.rb index 00180f3..f17ad45 100644 --- a/spec/defines/bsd_network_interface_spec.rb +++ b/spec/defines/bsd_network_interface_spec.rb @@ -1,152 +1,153 @@ require 'spec_helper' -describe "bsd::network::interface" do +describe 'bsd::network::interface' do on_supported_os.each do |os, facts| context "on #{os}" do let(:facts) { facts } - context "a basic configuration" do + context 'a basic configuration' do let(:title) { 'igb0' } - let(:params) { {:ensure => 'up'} } - - case facts[:osfamily] - when 'FreeBSD' - it { - should contain_bsd__network__interface('igb0').with_ensure('up') - should contain_bsd__network__interface('igb0').with_mtu(nil) - should contain_bsd__network__interface('igb0').with_parents(nil) - should contain_bsd_interface('igb0').with_ensure('up') - should contain_bsd_interface('igb0').with_mtu(nil) - should contain_bsd_interface('igb0').with_parents(nil) - } - end - end - - context "a basic configuration with an address" do - let(:title) { 'igb0' } - let(:params) { {:addresses => ['10.0.0.1/24'], :description => 'simple' } } - - case facts[:osfamily] - when 'FreeBSD' - it { - should contain_shellvar('ifconfig_igb0').with_value(/inet 10.0.0.1\/24/) - should contain_shellvar('ifconfig_igb0').with_target('/etc/rc.conf') - should contain_shellvar('ifconfig_igb0').that_notifies('Bsd_interface[igb0]') - should contain_bsd_interface('igb0').with_ensure('up') - should contain_bsd_interface('igb0').with_mtu(nil) - should contain_bsd_interface('igb0').with_parents(nil) - } - end - end - - context "a basic configuration with mtu" do - let(:title) { 'igb0' } - let(:params) { {:mtu => 9000, :description => 'simple mtu' } } - - case facts[:osfamily] - when 'FreeBSD' - it { - should contain_shellvar('ifconfig_igb0').with_value(/mtu 9000/) - should contain_shellvar('ifconfig_igb0').with_target('/etc/rc.conf') - should contain_bsd_interface('igb0').with_ensure('up') - should contain_bsd_interface('igb0').with_mtu(9000) - should contain_bsd_interface('igb0').with_parents(nil) - } - end - end - - context "a basic vlan interface with an address" do - let(:title) { 'vlan1' } - let(:params) { {:addresses => ['10.0.0.1/24'], :options => ['vlan 1', 'vlandev em0'] } } + let(:params) { { ensure: 'up' } } case facts[:osfamily] when 'FreeBSD' it do - should contain_shellvar('ifconfig_vlan1').with_value(/inet 10.0.0.1\/24 vlan 1 vlandev em0/) - should contain_shellvar('ifconfig_vlan1').with_ensure('present') - should contain_shellvar('ifconfig_vlan1').that_notifies('Bsd_interface[vlan1]') - should contain_bsd_interface('vlan1').that_requires('Shellvar[ifconfig_vlan1]') - should contain_bsd__network__interface('vlan1') + is_expected.to contain_bsd__network__interface('igb0').with_ensure('up') + is_expected.to contain_bsd__network__interface('igb0').with_mtu(nil) + is_expected.to contain_bsd__network__interface('igb0').with_parents(nil) + is_expected.to contain_bsd_interface('igb0').with_ensure('up') + is_expected.to contain_bsd_interface('igb0').with_mtu(nil) + is_expected.to contain_bsd_interface('igb0').with_parents(nil) + end + end + end - should contain_bsd_interface('vlan1').with_ensure('up') - should contain_bsd_interface('vlan1').with_mtu(nil) - should contain_bsd_interface('vlan1').with_parents(nil) + context 'a basic configuration with an address' do + let(:title) { 'igb0' } + let(:params) { { addresses: ['10.0.0.1/24'], description: 'simple' } } + + case facts[:osfamily] + when 'FreeBSD' + it do + is_expected.to contain_shellvar('ifconfig_igb0').with_value(/inet 10.0.0.1\/24/) + is_expected.to contain_shellvar('ifconfig_igb0').with_target('/etc/rc.conf') + is_expected.to contain_shellvar('ifconfig_igb0').that_notifies('Bsd_interface[igb0]') + is_expected.to contain_bsd_interface('igb0').with_ensure('up') + is_expected.to contain_bsd_interface('igb0').with_mtu(nil) + is_expected.to contain_bsd_interface('igb0').with_parents(nil) + end + end + end + + context 'a basic configuration with mtu' do + let(:title) { 'igb0' } + let(:params) { { mtu: 9000, description: 'simple mtu' } } + + case facts[:osfamily] + when 'FreeBSD' + it do + is_expected.to contain_shellvar('ifconfig_igb0').with_value(%r{mtu 9000}) + is_expected.to contain_shellvar('ifconfig_igb0').with_target('/etc/rc.conf') + is_expected.to contain_bsd_interface('igb0').with_ensure('up') + is_expected.to contain_bsd_interface('igb0').with_mtu(9000) + is_expected.to contain_bsd_interface('igb0').with_parents(nil) + end + end + end + + context 'a basic vlan interface with an address' do + let(:title) { 'vlan1' } + let(:params) { { addresses: ['10.0.0.1/24'], options: ['vlan 1', 'vlandev em0'] } } + + case facts[:osfamily] + when 'FreeBSD' + it do + is_expected.to contain_shellvar('ifconfig_vlan1').with_value(/inet 10.0.0.1\/24 vlan 1 vlandev em0/) + is_expected.to contain_shellvar('ifconfig_vlan1').with_ensure('present') + is_expected.to contain_shellvar('ifconfig_vlan1').that_notifies('Bsd_interface[vlan1]') + is_expected.to contain_bsd_interface('vlan1').that_requires('Shellvar[ifconfig_vlan1]') + is_expected.to contain_bsd__network__interface('vlan1') + + is_expected.to contain_bsd_interface('vlan1').with_ensure('up') + is_expected.to contain_bsd_interface('vlan1').with_mtu(nil) + is_expected.to contain_bsd_interface('vlan1').with_parents(nil) end end end end end - context "on OpenBSD" do - let(:facts) { {:kernel => 'OpenBSD'} } - context "a basic configuration" do + context 'on OpenBSD' do + let(:facts) { { kernel: 'OpenBSD' } } + context 'a basic configuration' do let(:title) { 'tun0' } - let(:params) { {:raw_values => ['just a test', 'up'], :description => 'simple' } } + let(:params) { { raw_values: ['just a test', 'up'], description: 'simple' } } it do - should contain_file('/etc/hostname.tun0').with_content(/description "simple"\njust a test\nup\n/) - should contain_bsd_interface('tun0').that_requires('File[/etc/hostname.tun0]') - should contain_bsd__network__interface('tun0') + is_expected.to contain_file('/etc/hostname.tun0').with_content(%r{description "simple"\njust a test\nup\n}) + is_expected.to contain_bsd_interface('tun0').that_requires('File[/etc/hostname.tun0]') + is_expected.to contain_bsd__network__interface('tun0') end end - context "a tun device" do + context 'a tun device' do let(:title) { 'tun0' } - let(:params) { {:raw_values => ['up','!/usr/local/bin/openvpn'] } } + let(:params) { { raw_values: ['up', '!/usr/local/bin/openvpn'] } } it do - should contain_file('/etc/hostname.tun0').with_content(/up\n!\/usr\/local\/bin\/openvpn/) + is_expected.to contain_file('/etc/hostname.tun0').with_content(/up\n!\/usr\/local\/bin\/openvpn/) end it do - should contain_file('/etc/hostname.tun0').that_notifies('Bsd_interface[tun0]') + is_expected.to contain_file('/etc/hostname.tun0').that_notifies('Bsd_interface[tun0]') end it do - should contain_bsd_interface('tun0').that_requires('File[/etc/hostname.tun0]') + is_expected.to contain_bsd_interface('tun0').that_requires('File[/etc/hostname.tun0]') end end - context "a vether device using addresses and values parameter" do + context 'a vether device using addresses and values parameter' do let(:title) { 'vether0' } - let(:params) { { - :addresses => [ '123.123.123.123/29', - '172.16.0.1/27', - 'fc01::/7', - '2001:100:fed:beef::/64', ], - :raw_values => [ 'up', ] + let(:params) do + { + addresses: ['123.123.123.123/29', + '172.16.0.1/27', + 'fc01::/7', + '2001:100:fed:beef::/64'], + raw_values: ['up'] } - } + end it do - should contain_file('/etc/hostname.vether0').with_content(/inet 123.123.123.123 255.255.255.248 NONE\ninet alias 172.16.0.1 255.255.255.224 NONE\ninet6 fc01:: 7\ninet6 alias 2001:100:fed:beef:: 64\nup\n/) + is_expected.to contain_file('/etc/hostname.vether0').with_content(%r{inet 123.123.123.123 255.255.255.248 NONE\ninet alias 172.16.0.1 255.255.255.224 NONE\ninet6 fc01:: 7\ninet6 alias 2001:100:fed:beef:: 64\nup\n}) end it do - should contain_file('/etc/hostname.vether0').that_notifies('Bsd_interface[vether0]') - should contain_bsd_interface('vether0').that_requires('File[/etc/hostname.vether0]') - should contain_bsd__network__interface('vether0') + is_expected.to contain_file('/etc/hostname.vether0').that_notifies('Bsd_interface[vether0]') + is_expected.to contain_bsd_interface('vether0').that_requires('File[/etc/hostname.vether0]') + is_expected.to contain_bsd__network__interface('vether0') end end - context "a vether device using values parameter only" do + context 'a vether device using values parameter only' do let(:title) { 'vether0' } - let(:params) { { - :raw_values => [ '123.123.123.123/29', - '172.16.0.1/27', - 'fc01::/7', - '2001:100:fed:beef::/64', - 'up', ] + let(:params) do + { + raw_values: ['123.123.123.123/29', + '172.16.0.1/27', + 'fc01::/7', + '2001:100:fed:beef::/64', + 'up'] } - } + end it do - should contain_file('/etc/hostname.vether0').with_content(/inet 123.123.123.123 255.255.255.248 NONE\ninet alias 172.16.0.1 255.255.255.224 NONE\ninet6 fc01:: 7\ninet6 alias 2001:100:fed:beef:: 64\nup\n/) + is_expected.to contain_file('/etc/hostname.vether0').with_content(%r{inet 123.123.123.123 255.255.255.248 NONE\ninet alias 172.16.0.1 255.255.255.224 NONE\ninet6 fc01:: 7\ninet6 alias 2001:100:fed:beef:: 64\nup\n}) end it do - should contain_file('/etc/hostname.vether0').that_notifies('Bsd_interface[vether0]') + is_expected.to contain_file('/etc/hostname.vether0').that_notifies('Bsd_interface[vether0]') end it do - should contain_bsd_interface('vether0').that_requires('File[/etc/hostname.vether0]') + is_expected.to contain_bsd_interface('vether0').that_requires('File[/etc/hostname.vether0]') end end end - end diff --git a/spec/defines/bsd_network_interface_trunk_spec.rb b/spec/defines/bsd_network_interface_trunk_spec.rb index baeb9ac..5f82fa2 100644 --- a/spec/defines/bsd_network_interface_trunk_spec.rb +++ b/spec/defines/bsd_network_interface_trunk_spec.rb @@ -1,70 +1,76 @@ require 'spec_helper' -describe "bsd::network::interface::trunk" do - context "on OpenBSD" do - let(:facts) { {:kernel => 'OpenBSD'} } +describe 'bsd::network::interface::trunk' do + context 'on OpenBSD' do + let(:facts) { { kernel: 'OpenBSD' } } let(:title) { 'trunk0' } - context " a minimal example" do - let(:params) { {:interface => ['em0', 'em1']} } + context ' a minimal example' do + let(:params) { { interface: %w(em0 em1) } } it do - should contain_bsd__network__interface__trunk('trunk0') - should contain_bsd__network__interface('trunk0').with_parents(['em0', 'em1']) - should contain_bsd_interface('trunk0') + is_expected.to contain_bsd__network__interface__trunk('trunk0') + is_expected.to contain_bsd__network__interface('trunk0').with_parents(%w(em0 em1)) + is_expected.to contain_bsd_interface('trunk0') end it do - should contain_file('/etc/hostname.trunk0').with_content(/trunkproto lacp trunkport em0 trunkport em1\nup\n/) + is_expected.to contain_file('/etc/hostname.trunk0').with_content(%r{trunkproto lacp trunkport em0 trunkport em1\nup\n}) end end - context "a medium example" do - let(:params) { {:interface => ['em0', 'em1'], :description => "TestNet"} } + context 'a medium example' do + let(:params) { { interface: %w(em0 em1), description: 'TestNet' } } it do - should contain_bsd__network__interface('trunk0').with_parents(['em0', 'em1']) + is_expected.to contain_bsd__network__interface('trunk0').with_parents(%w(em0 em1)) end it do - should contain_file('/etc/hostname.trunk0').with_content(/description \"TestNet\"\ntrunkproto lacp trunkport em0 trunkport em1\nup\n/) + is_expected.to contain_file('/etc/hostname.trunk0').with_content(%r{description \"TestNet\"\ntrunkproto lacp trunkport em0 trunkport em1\nup\n}) end end - context "an example with an address" do - let(:params) { { - :interface => ['em0', 'em1'], - :description => "TestNet", - :address => ['fc01::/64'] - } } - it do - should contain_bsd__network__interface('trunk0').with_parents(['em0', 'em1']) + context 'an example with an address' do + let(:params) do + { + interface: %w(em0 em1), + description: 'TestNet', + address: ['fc01::/64'] + } end it do - should contain_file('/etc/hostname.trunk0').with_content( - /description \"TestNet\"\ntrunkproto lacp trunkport em0 trunkport em1\ninet6 fc01:: 64\nup\n/) + is_expected.to contain_bsd__network__interface('trunk0').with_parents(%w(em0 em1)) + end + it do + is_expected.to contain_file('/etc/hostname.trunk0').with_content( + %r{description \"TestNet\"\ntrunkproto lacp trunkport em0 trunkport em1\ninet6 fc01:: 64\nup\n} + ) end end - context "an example with multiple addresses" do - let(:params) { { - :interface => ['em0', 'em1'], - :description => "TestNet", - :address => ['fc01::/64', '10.0.0.1/24'], - } } - it do - should contain_bsd__network__interface('trunk0').with_parents(['em0', 'em1']) + context 'an example with multiple addresses' do + let(:params) do + { + interface: %w(em0 em1), + description: 'TestNet', + address: ['fc01::/64', '10.0.0.1/24'] + } end it do - should contain_file('/etc/hostname.trunk0').with_content( - /description \"TestNet\"\ntrunkproto lacp trunkport em0 trunkport em1\ninet6 fc01:: 64\ninet 10.0.0.1 255.255.255.0 NONE\nup\n/) + is_expected.to contain_bsd__network__interface('trunk0').with_parents(%w(em0 em1)) + end + it do + is_expected.to contain_file('/etc/hostname.trunk0').with_content( + %r{description \"TestNet\"\ntrunkproto lacp trunkport em0 trunkport em1\ninet6 fc01:: 64\ninet 10.0.0.1 255.255.255.0 NONE\nup\n} + ) end end end - context "when a bad name is used" do - let(:facts) { {:kernel => 'OpenBSD'} } + context 'when a bad name is used' do + let(:facts) { { kernel: 'OpenBSD' } } let(:title) { 'notcorrect0' } - let(:params) { {:interface => ['em0', 'em1'], :description => "TestNet"} } + let(:params) { { interface: %w(em0 em1), description: 'TestNet' } } it do - expect { - should contain_bsd__network__interface__trunk('notcorrect0') - }.to raise_error(Puppet::Error, /does not match/) + expect do + is_expected.to contain_bsd__network__interface__trunk('notcorrect0') + end.to raise_error(Puppet::Error, %r{does not match}) end end end diff --git a/spec/defines/bsd_network_interface_vlan_spec.rb b/spec/defines/bsd_network_interface_vlan_spec.rb index 8843c4a..1851abf 100644 --- a/spec/defines/bsd_network_interface_vlan_spec.rb +++ b/spec/defines/bsd_network_interface_vlan_spec.rb @@ -1,95 +1,95 @@ require 'spec_helper' -describe "bsd::network::interface::vlan" do - context "on OpenBSD" do - let(:facts) { {:kernel => 'OpenBSD'} } +describe 'bsd::network::interface::vlan' do + context 'on OpenBSD' do + let(:facts) { { kernel: 'OpenBSD' } } let(:title) { 'vlan0' } - context " a minimal example" do - let(:params) { + context ' a minimal example' do + let(:params) do { - :id => 1, - :device => 'em0', - :address => ['10.0.0.1/24'], + id: 1, + device: 'em0', + address: ['10.0.0.1/24'] } - } - it do - should contain_bsd__network__interface__vlan('vlan0') - should contain_bsd__network__interface('vlan0').with_parents(['em0']) - should contain_bsd_interface('vlan0') end it do - should contain_file('/etc/hostname.vlan0').with_content(/vlan 1 vlandev em0\ninet 10.0.0.1 255.255.255.0 NONE\nup\n/) + is_expected.to contain_bsd__network__interface__vlan('vlan0') + is_expected.to contain_bsd__network__interface('vlan0').with_parents(['em0']) + is_expected.to contain_bsd_interface('vlan0') + end + it do + is_expected.to contain_file('/etc/hostname.vlan0').with_content(%r{vlan 1 vlandev em0\ninet 10.0.0.1 255.255.255.0 NONE\nup\n}) end end - context " a minimal example with multiple addresses" do - let(:params) { + context ' a minimal example with multiple addresses' do + let(:params) do { - :id => 1, - :device => 'em0', - :address => [ '10.0.0.1/24', '10.0.0.2/32', ], + id: 1, + device: 'em0', + address: ['10.0.0.1/24', '10.0.0.2/32'] } - } - it do - should contain_bsd__network__interface('vlan0').with_parents(['em0']) end it do - should contain_file('/etc/hostname.vlan0').with_content(/vlan 1 vlandev em0\ninet 10.0.0.1 255.255.255.0 NONE\ninet alias 10.0.0.2 255.255.255.255 NONE\nup\n/) + is_expected.to contain_bsd__network__interface('vlan0').with_parents(['em0']) + end + it do + is_expected.to contain_file('/etc/hostname.vlan0').with_content(%r{vlan 1 vlandev em0\ninet 10.0.0.1 255.255.255.0 NONE\ninet alias 10.0.0.2 255.255.255.255 NONE\nup\n}) end end - context " a bit more extensive example with values set" do - let(:params) { + context ' a bit more extensive example with values set' do + let(:params) do { - :id => 1, - :device => 'em0', - :address => ['10.0.0.1/24'], - :raw_values => ['!route add -net 10.10.10.0/24 10.0.0.254'], + id: 1, + device: 'em0', + address: ['10.0.0.1/24'], + raw_values: ['!route add -net 10.10.10.0/24 10.0.0.254'] } - } - it do - should contain_bsd__network__interface('vlan0').with_parents(['em0']) end it do - should contain_file('/etc/hostname.vlan0').with_content(/vlan 1 vlandev em0\ninet 10.0.0.1 255.255.255.0 NONE\n!route add -net 10.10.10.0\/24 10.0.0.254\nup\n/) + is_expected.to contain_bsd__network__interface('vlan0').with_parents(['em0']) + end + it do + is_expected.to contain_file('/etc/hostname.vlan0').with_content(/vlan 1 vlandev em0\ninet 10.0.0.1 255.255.255.0 NONE\n!route add -net 10.10.10.0\/24 10.0.0.254\nup\n/) end end end - context "when a bad name is used" do - let(:facts) { {:kernel => 'OpenBSD'} } + context 'when a bad name is used' do + let(:facts) { { kernel: 'OpenBSD' } } let(:title) { 'notcorrect0' } - let(:params) { + let(:params) do { - :id => 1, - :device => 'em0', - :address => ['10.0.0.1/24'], + id: 1, + device: 'em0', + address: ['10.0.0.1/24'] } - } + end it do - expect { - should contain_bsd__network__interface__vlan('notcorrect0') - }.to raise_error(Puppet::Error, /does not match/) + expect do + is_expected.to contain_bsd__network__interface__vlan('notcorrect0') + end.to raise_error(Puppet::Error, %r{does not match}) end end - context "on FreeBSD" do - let(:facts) { {:kernel => 'FreeBSD'} } + context 'on FreeBSD' do + let(:facts) { { kernel: 'FreeBSD' } } let(:title) { 'vlan0' } - context " a minimal example" do - let(:params) { + context ' a minimal example' do + let(:params) do { - :id => 1, - :device => 'em0', - :address => ['10.0.0.1/24'], + id: 1, + device: 'em0', + address: ['10.0.0.1/24'] } - } - it do - should contain_bsd__network__interface('vlan0').with_parents(['em0']) end it do - should contain_bsd__network__interface('vlan0').with_options(['vlan 1', 'vlandev em0']) + is_expected.to contain_bsd__network__interface('vlan0').with_parents(['em0']) end it do - should contain_bsd__network__interface('vlan0').with_raw_values(['10.0.0.1/24']) + is_expected.to contain_bsd__network__interface('vlan0').with_options(['vlan 1', 'vlandev em0']) + end + it do + is_expected.to contain_bsd__network__interface('vlan0').with_raw_values(['10.0.0.1/24']) end end end diff --git a/spec/defines/bsd_network_interface_wifi_spec.rb b/spec/defines/bsd_network_interface_wifi_spec.rb index 2fe9f3c..e2c7909 100644 --- a/spec/defines/bsd_network_interface_wifi_spec.rb +++ b/spec/defines/bsd_network_interface_wifi_spec.rb @@ -1,63 +1,62 @@ require 'spec_helper' -describe "bsd::network::interface::wifi" do - let(:facts) { {:kernel => 'OpenBSD'} } +describe 'bsd::network::interface::wifi' do + let(:facts) { { kernel: 'OpenBSD' } } let(:title) { 'athn0' } - context "with minimal parameters" do - let(:params) { {:network_name => 'myssid', :wpa_key => 'mysecretkey'} } + context 'with minimal parameters' do + let(:params) { { network_name: 'myssid', wpa_key: 'mysecretkey' } } it do - should contain_file('/etc/hostname.athn0').with_content(/nwid myssid wpakey mysecretkey\nup/) - should contain_bsd__network__interface__wifi('athn0') - should contain_bsd__network__interface('athn0') - should contain_bsd_interface('athn0') + is_expected.to contain_file('/etc/hostname.athn0').with_content(%r{nwid myssid wpakey mysecretkey\nup}) + is_expected.to contain_bsd__network__interface__wifi('athn0') + is_expected.to contain_bsd__network__interface('athn0') + is_expected.to contain_bsd_interface('athn0') end end - context "with more parameters" do - let(:params) { {:network_name => 'myssid', - :wpa_key => 'mysecretkey', - :description => 'something good', - :address => [ - '10.23.4.56/16', - '2001:471:4336:ff::1/64', - ], - :options => [ - 'chan 1', - 'media OFDM54', - 'mode 11g', - 'mediaopt hostap', - ] - } - } + context 'with more parameters' do + let(:params) do + { network_name: 'myssid', + wpa_key: 'mysecretkey', + description: 'something good', + address: [ + '10.23.4.56/16', + '2001:471:4336:ff::1/64' + ], + options: [ + 'chan 1', + 'media OFDM54', + 'mode 11g', + 'mediaopt hostap' + ] } + end it do - should_content = "inet 10.23.4.56 255.255.0.0 NONE\ninet6 2001:471:4336:ff::1 64\nnwid myssid wpakey mysecretkey chan 1 media OFDM54 mode 11g mediaopt hostap description \"something good\"\nup" - should contain_file('/etc/hostname.athn0').with_content(/#{should_content}/) + should_content = "inet 10.23.4.56 255.255.0.0 NONE\ninet6 2001:471:4336:ff::1 64\nnwid myssid wpakey mysecretkey chan 1 media OFDM54 mode 11g mediaopt hostap description \"something good\"\nup" + is_expected.to contain_file('/etc/hostname.athn0').with_content(%r{#{should_content}}) end end - context " a bit more extensive example with values set" do - let(:params) { {:network_name => 'myssid', - :wpa_key => 'mysecretkey', - :description => 'something good', - :address => [ - '10.23.4.56/16', - '2001:471:4336:ff::1/64', - ], - :options => [ - 'chan 1', - 'media OFDM54', - 'mode 11g', - 'mediaopt hostap', - ], - :raw_values => '!route add -net 10.10.10.0/24 10.0.0.254', - } - } + context ' a bit more extensive example with values set' do + let(:params) do + { network_name: 'myssid', + wpa_key: 'mysecretkey', + description: 'something good', + address: [ + '10.23.4.56/16', + '2001:471:4336:ff::1/64' + ], + options: [ + 'chan 1', + 'media OFDM54', + 'mode 11g', + 'mediaopt hostap' + ], + raw_values: '!route add -net 10.10.10.0/24 10.0.0.254' } + end it do - should_content = "inet 10.23.4.56 255.255.0.0 NONE\ninet6 2001:471:4336:ff::1 64\nnwid myssid wpakey mysecretkey chan 1 media OFDM54 mode 11g mediaopt hostap description \"something good\"\n!route add -net 10.10.10.0\/24 10.0.0.254\nup" - should contain_file('/etc/hostname.athn0').with_content(/#{should_content}/) + should_content = "inet 10.23.4.56 255.255.0.0 NONE\ninet6 2001:471:4336:ff::1 64\nnwid myssid wpakey mysecretkey chan 1 media OFDM54 mode 11g mediaopt hostap description \"something good\"\n!route add -net 10.10.10.0\/24 10.0.0.254\nup" + is_expected.to contain_file('/etc/hostname.athn0').with_content(%r{#{should_content}}) end end end - diff --git a/spec/functions/get_freebsd_rc_conf_shellvar_spec.rb b/spec/functions/get_freebsd_rc_conf_shellvar_spec.rb index a21eb10..7700e29 100644 --- a/spec/functions/get_freebsd_rc_conf_shellvar_spec.rb +++ b/spec/functions/get_freebsd_rc_conf_shellvar_spec.rb @@ -1,45 +1,44 @@ describe 'get_freebsd_rc_conf_shellvar' do - context 'setting only the mtu' do hash = { 'ifconfig_re0' => { - 'value' => 'mtu 9000', - }, + 'value' => 'mtu 9000' + } } c = { - "name" => 're0', - "mtu" => 9000, + 'name' => 're0', + 'mtu' => 9000 } - it { should run.with_params(c).and_return(hash) } + it { is_expected.to run.with_params(c).and_return(hash) } end context 'a full example' do hash = { 'ifconfig_re0' => { - 'value' => 'inet 10.0.1.12/24 mtu 9000', + 'value' => 'inet 10.0.1.12/24 mtu 9000' }, 'ifconfig_re0_alias0' => { - 'value' => 'inet 10.0.1.13/24', + 'value' => 'inet 10.0.1.13/24' }, 'ifconfig_re0_alias1' => { - 'value' => 'inet 10.0.1.14/24', - }, + 'value' => 'inet 10.0.1.14/24' + } } full = { - "name" => 're0', - "description" => "Uplink", - "addresses" => [ + 'name' => 're0', + 'description' => 'Uplink', + 'addresses' => [ '10.0.1.12/24', '10.0.1.13/24', - '10.0.1.14/24', + '10.0.1.14/24' ], - "options" => [ - 'mtu 9000', + 'options' => [ + 'mtu 9000' ] } - it { should run.with_params(full).and_return(hash) } + it { is_expected.to run.with_params(full).and_return(hash) } end end diff --git a/spec/functions/get_openbsd_hostname_if_content_spec.rb b/spec/functions/get_openbsd_hostname_if_content_spec.rb index 39e964c..d2cc840 100644 --- a/spec/functions/get_openbsd_hostname_if_content_spec.rb +++ b/spec/functions/get_openbsd_hostname_if_content_spec.rb @@ -1,32 +1,31 @@ require 'spec_helper' -describe "get_openbsd_hostname_if_content" do - - context "with mtu set" do +describe 'get_openbsd_hostname_if_content' do + context 'with mtu set' do config = { - "name" => 'em0', - "mtu" => 9000, + 'name' => 'em0', + 'mtu' => 9000 } - it { should run.with_params(config).and_return("mtu 9000") } + it { is_expected.to run.with_params(config).and_return('mtu 9000') } end - context "with an address set" do + context 'with an address set' do config = { - "name" => 'em0', - "addresses" => ['fc01::/64'], + 'name' => 'em0', + 'addresses' => ['fc01::/64'] } - it { should run.with_params(config).and_return("inet6 fc01:: 64") } + it { is_expected.to run.with_params(config).and_return('inet6 fc01:: 64') } end - context "tun interface" do + context 'tun interface' do config = { - "name" => 'tun0', - "type" => 'tun', - "raw_values" => ['up','!/usr/local/bin/openvpn'], + 'name' => 'tun0', + 'type' => 'tun', + 'raw_values' => ['up', '!/usr/local/bin/openvpn'] } - it { should run.with_params(config).and_return("up\n!/usr/local/bin/openvpn") } + it { is_expected.to run.with_params(config).and_return("up\n!/usr/local/bin/openvpn") } end end diff --git a/spec/functions/get_rc_conf_vlan_spec.rb b/spec/functions/get_rc_conf_vlan_spec.rb index 7a24c1d..ea06857 100644 --- a/spec/functions/get_rc_conf_vlan_spec.rb +++ b/spec/functions/get_rc_conf_vlan_spec.rb @@ -2,17 +2,17 @@ require 'spec_helper' describe 'get_rc_conf_vlan' do context 'with a simple config' do - desired = ["vlan 1", "vlandev em0"] + desired = ['vlan 1', 'vlandev em0'] config = { - "name" => 'vlan1', - "description" => "Trees", - "device" => 'em0', - "id" => 1, - "address" => [ - '10.0.1.12/24', - ], + 'name' => 'vlan1', + 'description' => 'Trees', + 'device' => 'em0', + 'id' => 1, + 'address' => [ + '10.0.1.12/24' + ] } - it { should run.with_params(config).and_return(desired) } + it { is_expected.to run.with_params(config).and_return(desired) } end end diff --git a/spec/unit/bsd/hostname_if/carp_spec.rb b/spec/unit/bsd/hostname_if/carp_spec.rb index 673e769..c1c25d6 100644 --- a/spec/unit/bsd/hostname_if/carp_spec.rb +++ b/spec/unit/bsd/hostname_if/carp_spec.rb @@ -5,40 +5,38 @@ describe 'Carp' do describe 'initialize' do context 'when minimal configuration is passed' do - it 'should not error' do - expect { - subject.new({ - :id => '1', - :device => 'em0', - :address => ['10.0.0.1/24'], - }) - }.to_not raise_error + it 'does not error' do + expect do + subject.new(id: '1', + device: 'em0', + address: ['10.0.0.1/24']) + end.not_to raise_error end end end describe 'content' do - it 'should support a full example' do + it 'supports a full example' do c = { - :id => '1', - :device => 'em0', - :address => ['10.0.0.1/24'], - :advbase => '1', - :advskew => '0', - :pass => 'TopSecret', + id: '1', + device: 'em0', + address: ['10.0.0.1/24'], + advbase: '1', + advskew: '0', + pass: 'TopSecret' } - expect(subject.new(c).content).to match(/vhid 1 pass TopSecret carpdev em0 advbase 1 advskew 0\ninet 10.0.0.1 255.255.255.0 NONE/) + expect(subject.new(c).content).to match(%r{vhid 1 pass TopSecret carpdev em0 advbase 1 advskew 0\ninet 10.0.0.1 255.255.255.0 NONE}) end - it 'should support a partial example' do + it 'supports a partial example' do c = { - :id => '1', - :device => 'em0', - :address => ['10.0.0.1/24'], - :advbase => '1', - :advskew => '0', + id: '1', + device: 'em0', + address: ['10.0.0.1/24'], + advbase: '1', + advskew: '0' } - expect(subject.new(c).content).to match(/vhid 1 carpdev em0 advbase 1 advskew 0\ninet 10.0.0.1 255.255.255.0 NONE/) + expect(subject.new(c).content).to match(%r{vhid 1 carpdev em0 advbase 1 advskew 0\ninet 10.0.0.1 255.255.255.0 NONE}) end end end diff --git a/spec/unit/bsd/hostname_if/inet_spec.rb b/spec/unit/bsd/hostname_if/inet_spec.rb index 752482e..1aeff94 100644 --- a/spec/unit/bsd/hostname_if/inet_spec.rb +++ b/spec/unit/bsd/hostname_if/inet_spec.rb @@ -2,76 +2,76 @@ require 'puppet_x/bsd/hostname_if/inet' describe 'PuppetX::BSD::Hostname_if::Inet' do describe 'initialize' do - it "should raise an error if argument is not of correct type" do - a = {:one => '1'} + it 'raises an error if argument is not of correct type' do + a = { one: '1' } expect { PuppetX::BSD::Hostname_if::Inet.new(a) }.to raise_error end - it "should not raise an error if argument is of correct type" do + it 'does not raise an error if argument is of correct type' do a = ['10.0.0.0/24'] - expect { PuppetX::BSD::Hostname_if::Inet.new(a) }.to_not raise_error + expect { PuppetX::BSD::Hostname_if::Inet.new(a) }.not_to raise_error b = '10.0.0.0/24' - expect { PuppetX::BSD::Hostname_if::Inet.new(b) }.to_not raise_error + expect { PuppetX::BSD::Hostname_if::Inet.new(b) }.not_to raise_error end end describe 'process' do context 'On OpenBSD 5.6' do - it "should yield the the dynamic addressing is specified for all AF with rtsol" do - a = [ - 'dhcp', - 'rtsol', - ] + it 'yields the the dynamic addressing is specified for all AF with rtsol' do + a = %w( + dhcp + rtsol + ) expect(Facter).to receive(:value).with('kernelversion').at_least(:once).and_return('5.6') - expect {|b| + expect do |b| PuppetX::BSD::Hostname_if::Inet.new(a).process(&b) - }.to yield_successive_args('dhcp','rtsol') + end.to yield_successive_args('dhcp', 'rtsol') end - it "should yield the the dynamic addressing is specified for all AF with inet6 autoconf" do + it 'yields the the dynamic addressing is specified for all AF with inet6 autoconf' do a = [ 'dhcp', - 'inet6 autoconf', + 'inet6 autoconf' ] expect(Facter).to receive(:value).with('kernelversion').at_least(:once).and_return('5.6') - expect {|b| + expect do |b| PuppetX::BSD::Hostname_if::Inet.new(a).process(&b) - }.to yield_successive_args('dhcp','rtsol') + end.to yield_successive_args('dhcp', 'rtsol') end end context 'On OpenBSD 5.7' do - it "should yield the the dynamic addressing is specified for all AF with rtsol" do - a = [ - 'dhcp', - 'rtsol', - ] + it 'yields the the dynamic addressing is specified for all AF with rtsol' do + a = %w( + dhcp + rtsol + ) expect(Facter).to receive(:value).with('kernelversion').at_least(:once).and_return('5.7') - expect {|b| + expect do |b| PuppetX::BSD::Hostname_if::Inet.new(a).process(&b) - }.to yield_successive_args('dhcp','inet6 autoconf') + end.to yield_successive_args('dhcp', 'inet6 autoconf') end - it "should yield the the dynamic addressing is specified for all AF with inet6 autoconf" do + it 'yields the the dynamic addressing is specified for all AF with inet6 autoconf' do a = [ 'dhcp', - 'inet6 autoconf', + 'inet6 autoconf' ] expect(Facter).to receive(:value).with('kernelversion').at_least(:once).and_return('5.7') - expect {|b| + expect do |b| PuppetX::BSD::Hostname_if::Inet.new(a).process(&b) - }.to yield_successive_args('dhcp','inet6 autoconf') + end.to yield_successive_args('dhcp', 'inet6 autoconf') end end - it "should yield multiple addresses when specified" do + it 'yields multiple addresses when specified' do a = [ '123.123.123.123/29', '172.16.0.1/27', 'fc01::/7', - '2001:100:fed:beef::/64', + '2001:100:fed:beef::/64' ] - expect {|b| + expect do |b| PuppetX::BSD::Hostname_if::Inet.new(a).process(&b) - }.to yield_successive_args( + end.to yield_successive_args( 'inet 123.123.123.123 255.255.255.248 NONE', 'inet alias 172.16.0.1 255.255.255.224 NONE', 'inet6 fc01:: 7', diff --git a/spec/unit/bsd/hostname_if/pfsync_spec.rb b/spec/unit/bsd/hostname_if/pfsync_spec.rb index 972bc11..838d85e 100644 --- a/spec/unit/bsd/hostname_if/pfsync_spec.rb +++ b/spec/unit/bsd/hostname_if/pfsync_spec.rb @@ -4,17 +4,17 @@ describe 'Pfsync' do subject(:pfif) { Hostname_if::Pfsync } describe 'content' do - it 'should support a minimal example' do - c = { } - expect(pfif.new(c).content).to match(/-syncdev -syncpeer maxupd 128 -defer/) + it 'supports a minimal example' do + c = {} + expect(pfif.new(c).content).to match(%r{-syncdev -syncpeer maxupd 128 -defer}) end - it 'should support a partial example' do + it 'supports a partial example' do c = { - :syncdev => 'em0', - :syncpeer => '10.0.0.222', + syncdev: 'em0', + syncpeer: '10.0.0.222' } - expect(pfif.new(c).content).to match(/syncdev em0 syncpeer 10.0.0.222 maxupd 128 -defer/) + expect(pfif.new(c).content).to match(%r{syncdev em0 syncpeer 10.0.0.222 maxupd 128 -defer}) end end end diff --git a/spec/unit/bsd/hostname_if/trunk_spec.rb b/spec/unit/bsd/hostname_if/trunk_spec.rb index 0819e06..76be5e3 100644 --- a/spec/unit/bsd/hostname_if/trunk_spec.rb +++ b/spec/unit/bsd/hostname_if/trunk_spec.rb @@ -4,25 +4,25 @@ describe 'Trunk' do subject(:trunkif) { Hostname_if::Trunk } describe 'content' do - it 'should support a full example' do + it 'supports a full example' do c = { - :proto => 'lacp', - :interface => ['em0'], + proto: 'lacp', + interface: ['em0'] } - expect(trunkif.new(c).content).to match(/trunkproto lacp trunkport em0/) + expect(trunkif.new(c).content).to match(%r{trunkproto lacp trunkport em0}) end - it 'should support a partial example' do + it 'supports a partial example' do c = { - :proto => 'lacp', - :interface => [ - 'em0', - 'em1', - 'em2', - 'em3', - ] + proto: 'lacp', + interface: %w( + em0 + em1 + em2 + em3 + ) } - expect(trunkif.new(c).content).to match(/trunkproto lacp trunkport em0 trunkport em1 trunkport em2 trunkport em3/) + expect(trunkif.new(c).content).to match(%r{trunkproto lacp trunkport em0 trunkport em1 trunkport em2 trunkport em3}) end end end diff --git a/spec/unit/bsd/hostname_if/vlan_spec.rb b/spec/unit/bsd/hostname_if/vlan_spec.rb index d5336c3..7f60e60 100644 --- a/spec/unit/bsd/hostname_if/vlan_spec.rb +++ b/spec/unit/bsd/hostname_if/vlan_spec.rb @@ -4,50 +4,50 @@ describe 'Vlan' do subject(:vlanif) { Hostname_if::Vlan } describe 'content' do - it 'should support a full example' do + it 'supports a full example' do c = { - :id => 1, - :device => 'em0', - :address => ['10.0.0.1/24'], + id: 1, + device: 'em0', + address: ['10.0.0.1/24'] } wanted = [ - 'vlan 1 vlandev em0', - 'inet 10.0.0.1 255.255.255.0 NONE', + 'vlan 1 vlandev em0', + 'inet 10.0.0.1 255.255.255.0 NONE' ] expect(vlanif.new(c).content).to match(wanted.join('\n')) end - it 'should support a partial example' do + it 'supports a partial example' do c = { - :id => 1, - :device => 'em0', - :address => ['10.0.0.1/24'], + id: 1, + device: 'em0', + address: ['10.0.0.1/24'] } wanted = [ - 'vlan 1 vlandev em0', - 'inet 10.0.0.1 255.255.255.0 NONE', + 'vlan 1 vlandev em0', + 'inet 10.0.0.1 255.255.255.0 NONE' ] expect(vlanif.new(c).content).to match(wanted.join('\n')) end - it 'should support a allow an array of addresses' do + it 'supports a allow an array of addresses' do c = { - :id => 1, - :device => 'em0', - :address => [ + id: 1, + device: 'em0', + address: [ '10.0.0.1/24', '10.1.0.1/24', 'fc00:1::/64', - 'fc00:2::/64', + 'fc00:2::/64' ] } wanted = [ - 'vlan 1 vlandev em0', - 'inet 10.0.0.1 255.255.255.0 NONE', - 'inet alias 10.1.0.1 255.255.255.0 NONE', - 'inet6 fc00:1:: 64', - 'inet6 alias fc00:2:: 64' + 'vlan 1 vlandev em0', + 'inet 10.0.0.1 255.255.255.0 NONE', + 'inet alias 10.1.0.1 255.255.255.0 NONE', + 'inet6 fc00:1:: 64', + 'inet6 alias fc00:2:: 64' ] expect(vlanif.new(c).content).to match(wanted.join('\n')) @@ -55,23 +55,23 @@ describe 'Vlan' do end describe '#values' do - it 'should return a list of values for a full example' do + it 'returns a list of values for a full example' do c = { - :id => 1, - :device => 'em0', - :address => [ + id: 1, + device: 'em0', + address: [ '10.0.0.1/24', '10.1.0.1/24', 'fc00:1::/64', - 'fc00:2::/64', + 'fc00:2::/64' ] } wanted = [ - 'vlan 1 vlandev em0', - 'inet 10.0.0.1 255.255.255.0 NONE', - 'inet alias 10.1.0.1 255.255.255.0 NONE', - 'inet6 fc00:1:: 64', - 'inet6 alias fc00:2:: 64' + 'vlan 1 vlandev em0', + 'inet 10.0.0.1 255.255.255.0 NONE', + 'inet alias 10.1.0.1 255.255.255.0 NONE', + 'inet6 fc00:1:: 64', + 'inet6 alias fc00:2:: 64' ] expect(vlanif.new(c).values).to match_array(wanted) diff --git a/spec/unit/bsd/hostname_if/wifi_spec.rb b/spec/unit/bsd/hostname_if/wifi_spec.rb index 33e3f0d..0c80f01 100644 --- a/spec/unit/bsd/hostname_if/wifi_spec.rb +++ b/spec/unit/bsd/hostname_if/wifi_spec.rb @@ -4,37 +4,36 @@ describe 'Wifi' do subject(:wifiif) { Hostname_if::Wifi } describe 'content' do - it 'should support a minimal example' do + it 'supports a minimal example' do c = { - :network_name => 'myssid', + network_name: 'myssid' } - expect(wifiif.new(c).content).to match(/nwid myssid/) + expect(wifiif.new(c).content).to match(%r{nwid myssid}) end - it 'should support a minimal example with dhcp' do + it 'supports a minimal example with dhcp' do c = { - :network_name => 'myssid', - :address => ['dhcp'], + network_name: 'myssid', + address: ['dhcp'] } - expect(wifiif.new(c).content).to match(/dhcp\nnwid myssid/) + expect(wifiif.new(c).content).to match(%r{dhcp\nnwid myssid}) end - it 'should support a partial example' do + it 'supports a partial example' do c = { - :network_name => 'myssid', - :wpa_key => 'mykey', + network_name: 'myssid', + wpa_key: 'mykey' } - expect(wifiif.new(c).content).to match(/nwid myssid wpakey mykey/) + expect(wifiif.new(c).content).to match(%r{nwid myssid wpakey mykey}) end - it 'should support a full example' do + it 'supports a full example' do c = { - :network_name => 'myssid', - :wpa_key => 'mykey', - :address => ['10.0.0.1/24'], + network_name: 'myssid', + wpa_key: 'mykey', + address: ['10.0.0.1/24'] } - expect(wifiif.new(c).content).to match(/inet 10.0.0.1 255.255.255.0 NONE\nnwid myssid wpakey mykey/) + expect(wifiif.new(c).content).to match(%r{inet 10.0.0.1 255.255.255.0 NONE\nnwid myssid wpakey mykey}) end end end - diff --git a/spec/unit/bsd/hostname_if_spec.rb b/spec/unit/bsd/hostname_if_spec.rb index d929be8..43fa8ec 100644 --- a/spec/unit/bsd/hostname_if_spec.rb +++ b/spec/unit/bsd/hostname_if_spec.rb @@ -5,232 +5,231 @@ describe 'Hostname_if' do describe 'initialize' do context 'when minimal configuration is passed' do - it 'should not error' do - expect { hif.new({:desc => 'String goes here'}) }.to_not raise_error + it 'does not error' do + expect { hif.new(desc: 'String goes here') }.not_to raise_error end end end - describe "content" do - it "should append the options string on the first line when options are present" do + describe 'content' do + it 'appends the options string on the first line when options are present' do c = { - :options => ["mtu 1500"] + options: ['mtu 1500'] } - expect(hif.new(c).content.split("\n").first).to match(/mtu 1500/) + expect(hif.new(c).content.split("\n").first).to match(%r{mtu 1500}) end - it "should append multiple options on the first line when multiple options are present" do + it 'appends multiple options on the first line when multiple options are present' do c = { - :options => [ - "mtu 1500", - "media 100baseTX", - ], + options: [ + 'mtu 1500', + 'media 100baseTX' + ] } - expect(hif.new(c).content.split("\n").first).to match(/mtu 1500/) - expect(hif.new(c).content.split("\n").first).to match(/media 100baseTX/) + expect(hif.new(c).content.split("\n").first).to match(%r{mtu 1500}) + expect(hif.new(c).content.split("\n").first).to match(%r{media 100baseTX}) end - it "should append multiple options on the first line with a description" do + it 'appends multiple options on the first line with a description' do c = { - :desc => "Default interface", - :options => [ - "mtu 1500", - "media 100baseTX", - ], + desc: 'Default interface', + options: [ + 'mtu 1500', + 'media 100baseTX' + ] } - expect(hif.new(c).content.split("\n").first).to match(/mtu 1500/) - expect(hif.new(c).content.split("\n").first).to match(/media 100baseTX/) - expect(hif.new(c).content.split("\n").first).to match(/Default interface/) + expect(hif.new(c).content.split("\n").first).to match(%r{mtu 1500}) + expect(hif.new(c).content.split("\n").first).to match(%r{media 100baseTX}) + expect(hif.new(c).content.split("\n").first).to match(%r{Default interface}) end - it "should set the the dynamic property of the interface is specified" do + it 'sets the the dynamic property of the interface is specified' do c = { - :raw_values => ['dhcp'], + raw_values: ['dhcp'] } - expect(hif.new(c).content).to match(/^dhcp/) + expect(hif.new(c).content).to match(%r{^dhcp}) end context 'with rtsol given for IPv6' do - it "should set the the dynamic property of the interface is specified for all AF setting inet6 autoconf for rtsol" do + it 'sets the the dynamic property of the interface is specified for all AF setting inet6 autoconf for rtsol' do c = { - :raw_values => [ - 'dhcp', - 'rtsol', - ] + raw_values: %w( + dhcp + rtsol + ) } - expect(hif.new(c).content).to match(/^dhcp/) - expect(hif.new(c).content).to match(/^rtsol/) + expect(hif.new(c).content).to match(%r{^dhcp}) + expect(hif.new(c).content).to match(%r{^rtsol}) end end - it "should set the primary interface address and prefix" do + it 'sets the primary interface address and prefix' do c = { - :raw_values => ['fc01::/7'], + raw_values: ['fc01::/7'] } - expect(hif.new(c).content).to match(/fc01:: 7/) + expect(hif.new(c).content).to match(%r{fc01:: 7}) end - it "should set multiple interface addresses" do + it 'sets multiple interface addresses' do c = { - :raw_values => [ + raw_values: [ '123.123.123.123/29', '172.16.0.1/27', 'fc01::/7', - '2001:100:fed:beef::/64', + '2001:100:fed:beef::/64' ] } - expect(hif.new(c).content).to match(/inet 123.123.123.123 255.255.255.248 NONE/) - expect(hif.new(c).content).to match(/inet alias 172.16.0.1 255.255.255.224 NONE/) - expect(hif.new(c).content).to match(/inet6 fc01:: 7/) - expect(hif.new(c).content).to match(/inet6 alias 2001:100:fed:beef:: 64/) + expect(hif.new(c).content).to match(%r{inet 123.123.123.123 255.255.255.248 NONE}) + expect(hif.new(c).content).to match(%r{inet alias 172.16.0.1 255.255.255.224 NONE}) + expect(hif.new(c).content).to match(%r{inet6 fc01:: 7}) + expect(hif.new(c).content).to match(%r{inet6 alias 2001:100:fed:beef:: 64}) end - it "should set everything when provided" do + it 'sets everything when provided' do c = { - :desc => "Default interface", - :options => [ - "mtu 1500", - "media 100baseTX", + desc: 'Default interface', + options: [ + 'mtu 1500', + 'media 100baseTX' ], - :raw_values => [ + raw_values: [ '123.123.123.123/29', '172.16.0.1/27', 'fc01::/7', - '2001:100:fed:beef::/64', + '2001:100:fed:beef::/64' ] } - expect(hif.new(c).content).to match(/inet 123.123.123.123 255.255.255.248 NONE/) - expect(hif.new(c).content).to match(/inet alias 172.16.0.1 255.255.255.224 NONE/) - expect(hif.new(c).content).to match(/inet6 fc01:: 7/) - expect(hif.new(c).content).to match(/inet6 alias 2001:100:fed:beef:: 64/) - expect(hif.new(c).content.split("\n").first).to match(/mtu 1500/) - expect(hif.new(c).content.split("\n").first).to match(/media 100baseTX/) - expect(hif.new(c).content.split("\n").first).to match(/Default interface/) + expect(hif.new(c).content).to match(%r{inet 123.123.123.123 255.255.255.248 NONE}) + expect(hif.new(c).content).to match(%r{inet alias 172.16.0.1 255.255.255.224 NONE}) + expect(hif.new(c).content).to match(%r{inet6 fc01:: 7}) + expect(hif.new(c).content).to match(%r{inet6 alias 2001:100:fed:beef:: 64}) + expect(hif.new(c).content.split("\n").first).to match(%r{mtu 1500}) + expect(hif.new(c).content.split("\n").first).to match(%r{media 100baseTX}) + expect(hif.new(c).content.split("\n").first).to match(%r{Default interface}) end - it "should clear the description string when called multiple times" do + it 'clears the description string when called multiple times' do c = { - :desc => "Default interface", - :options => [ - "mtu 1500", - "media 100baseTX", + desc: 'Default interface', + options: [ + 'mtu 1500', + 'media 100baseTX' ], - :raw_values => [ + raw_values: [ '123.123.123.123/29', '172.16.0.1/27', 'fc01::/7', - '2001:100:fed:beef::/64', + '2001:100:fed:beef::/64' ] } - expect(hif.new(c).content.split("\n").first).to_not match(/Default interface.*Default interface/) - expect(hif.new(c).content.split("\n").first).to_not match(/Default interface.*Default interface/) - expect(hif.new(c).content.split("\n").first).to_not match(/Default interface.*Default interface/) + expect(hif.new(c).content.split("\n").first).not_to match(%r{Default interface.*Default interface}) + expect(hif.new(c).content.split("\n").first).not_to match(%r{Default interface.*Default interface}) + expect(hif.new(c).content.split("\n").first).not_to match(%r{Default interface.*Default interface}) end - it "should not raise error when options are :udnef" do + it 'does not raise error when options are :udnef' do c = { - :desc => :undef, - :options => :undef, - :raw_values => [ + desc: :undef, + options: :undef, + raw_values: [ '123.123.123.123/29', '172.16.0.1/27', 'fc01::/7', - '2001:100:fed:beef::/64', + '2001:100:fed:beef::/64' ] } - expect { hif.new(c).content }.to_not raise_error + expect { hif.new(c).content }.not_to raise_error end - it "should support setting the interface to up" do + it 'supports setting the interface to up' do c = { - :raw_values => [ - 'up', + raw_values: [ + 'up' ] } - expect(hif.new(c).content).to match(/^up/) + expect(hif.new(c).content).to match(%r{^up}) end - it "should support setting the interface to down" do + it 'supports setting the interface to down' do c = { - :raw_values => [ - 'down', + raw_values: [ + 'down' ] } - expect(hif.new(c).content).to match(/^down/) + expect(hif.new(c).content).to match(%r{^down}) end - it "should support setting the interface to up and setting the description" do + it 'supports setting the interface to up and setting the description' do c = { - :desc => "I am an interface", - :raw_values => [ - 'up', + desc: 'I am an interface', + raw_values: [ + 'up' ] } - expect(hif.new(c).content).to match(/^description "I am an interface"\nup/) + expect(hif.new(c).content).to match(%r{^description "I am an interface"\nup}) end - it "should support the !command syntax in the hostname.if(5) manpage" do + it 'supports the !command syntax in the hostname.if(5) manpage' do c = { - :desc => "Uplink", - :raw_values => [ + desc: 'Uplink', + raw_values: [ '10.0.1.12/24', '10.0.1.13/24', '10.0.1.14/24', '10.0.1.15/24', '10.0.1.16/24', '!route add 65.65.65.65 10.0.1.13', - 'up', + 'up' ], - :options => [ + options: [ 'media 100baseTX' ] } - expect(hif.new(c).content).to match(/10.0.1.12 255.255.255.0/) - expect(hif.new(c).content).to match(/10.0.1.13 255.255.255.0/) - expect(hif.new(c).content).to match(/10.0.1.14 255.255.255.0/) - expect(hif.new(c).content).to match(/10.0.1.15 255.255.255.0/) - expect(hif.new(c).content).to match(/10.0.1.16 255.255.255.0/) - expect(hif.new(c).content).to match(/^!route add 65.65.65.65 10.0.1.13$/) - expect(hif.new(c).content).to match(/^up$/) - expect(hif.new(c).content).to match(/media 100baseTX/) - expect(hif.new(c).content).to match(/description "?Uplink"?/) + expect(hif.new(c).content).to match(%r{10.0.1.12 255.255.255.0}) + expect(hif.new(c).content).to match(%r{10.0.1.13 255.255.255.0}) + expect(hif.new(c).content).to match(%r{10.0.1.14 255.255.255.0}) + expect(hif.new(c).content).to match(%r{10.0.1.15 255.255.255.0}) + expect(hif.new(c).content).to match(%r{10.0.1.16 255.255.255.0}) + expect(hif.new(c).content).to match(%r{^!route add 65.65.65.65 10.0.1.13$}) + expect(hif.new(c).content).to match(%r{^up$}) + expect(hif.new(c).content).to match(%r{media 100baseTX}) + expect(hif.new(c).content).to match(%r{description "?Uplink"?}) end - it "should fail when the type is not a string" do + it 'fails when the type is not a string' do c = { - :type => ['gif'], - :desc => "I am a tunnel interface", - :raw_values => [ - 'up', + type: ['gif'], + desc: 'I am a tunnel interface', + raw_values: [ + 'up' ] } - expect { hif.new(c).content }.to raise_error(ArgumentError, /Config option.*must be a String/) + expect { hif.new(c).content }.to raise_error(ArgumentError, %r{Config option.*must be a String}) end - it "should support the gre interface type" do + it 'supports the gre interface type' do c = { - :type => 'gre', - :raw_values => [ + type: 'gre', + raw_values: [ '192.168.100.1 192.168.100.2 netmask 0xffffffff link0 up', - 'tunnel 10.0.1.30 10.0.1.31', + 'tunnel 10.0.1.30 10.0.1.31' ] } - expect(hif.new(c).content).to match(/192.168.100.1 192.168.100.2 netmask 0xffffffff link0 up/) - expect(hif.new(c).content).to match(/tunnel 10.0.1.30 10.0.1.31/) + expect(hif.new(c).content).to match(%r{192.168.100.1 192.168.100.2 netmask 0xffffffff link0 up}) + expect(hif.new(c).content).to match(%r{tunnel 10.0.1.30 10.0.1.31}) end - it "should support the tun interface type" do + it 'supports the tun interface type' do c = { - :type => 'tun', - :raw_values => [ + type: 'tun', + raw_values: [ 'up', - '!/usr/local/sbin/openvpn --daemon --config /etc/openvpn/vpn.ovpn --cd /etc/openvpn', + '!/usr/local/sbin/openvpn --daemon --config /etc/openvpn/vpn.ovpn --cd /etc/openvpn' ] } content = hif.new(c).content - expect(content).to match(/^up$/) + expect(content).to match(%r{^up$}) expect(content).to match(/^!\/usr\/local\/sbin\/openvpn/) end - end end diff --git a/spec/unit/bsd/ifconfig_spec.rb b/spec/unit/bsd/ifconfig_spec.rb index d2a2a8e..b820c85 100644 --- a/spec/unit/bsd/ifconfig_spec.rb +++ b/spec/unit/bsd/ifconfig_spec.rb @@ -1,78 +1,75 @@ require 'puppet_x/bsd/ifconfig' describe 'PuppetX::BSD::Ifconfig' do - context "on OpenBSD" do + context 'on OpenBSD' do context '#parse' do - it "should return the desired hash for a single interface" do - output = File.read("spec/fixtures/ifconfig_openbsd.em.up") + it 'returns the desired hash for a single interface' do + output = File.read('spec/fixtures/ifconfig_openbsd.em.up') - wanted = {:em0=>{:flags=>["UP", "BROADCAST", "RUNNING", "SIMPLEX", "MULTICAST"], :mtu=>"1500", :inet6=>["fe80::200:9999:ffff:6404/64", "2fff:fff:ffff::10:10/64"], :inet=>"10.0.0.10/255.255.255.0"}} + wanted = { em0: { flags: %w(UP BROADCAST RUNNING SIMPLEX MULTICAST), mtu: '1500', inet6: ['fe80::200:9999:ffff:6404/64', '2fff:fff:ffff::10:10/64'], inet: '10.0.0.10/255.255.255.0' } } expect(PuppetX::BSD::Ifconfig.new(output).parse).to eq(wanted) end - it "should return the desired hash for a full example" do - output = File.read("spec/fixtures/ifconfig_openbsd.full") + it 'returns the desired hash for a full example' do + output = File.read('spec/fixtures/ifconfig_openbsd.full') - wanted = {:lo0=>{:flags=>["UP", "LOOPBACK", "RUNNING", "MULTICAST"], :mtu=>"32768", :inet6=>["fe80::1/64", "::1/128"], :inet=>"127.0.0.1/255.0.0.0"}, :em0=>{:flags=>["UP", "BROADCAST", "RUNNING", "SIMPLEX", "MULTICAST"], :mtu=>"1500", :inet=>"10.0.31.2/255.255.255.252", :inet6=>["fe80::200:24ff:fed0:6404/64", "2001:1234:abcd:f::10/80"]}, :em1=>{:flags=>["BROADCAST", "SIMPLEX", "MULTICAST"], :mtu=>"1500"}, :em2=>{:flags=>["BROADCAST", "SIMPLEX", "MULTICAST"], :mtu=>"1500"}, :em3=>{:flags=>["BROADCAST", "SIMPLEX", "MULTICAST"], :mtu=>"1500"}, :em4=>{:flags=>["UP", "BROADCAST", "RUNNING", "PROMISC", "ALLMULTI", "SIMPLEX", "MULTICAST"], :mtu=>"1500"}, :em5=>{:flags=>["UP", "BROADCAST", "RUNNING", "PROMISC", "ALLMULTI", "SIMPLEX", "MULTICAST"], :mtu=>"1500"}, :em6=>{:flags=>["UP", "BROADCAST", "RUNNING", "PROMISC", "ALLMULTI", "SIMPLEX", "MULTICAST"], :mtu=>"1500"}, :em7=>{:flags=>["UP", "BROADCAST", "RUNNING", "PROMISC", "ALLMULTI", "SIMPLEX", "MULTICAST"], :mtu=>"1500"}, :vether0=>{:flags=>["UP", "BROADCAST", "RUNNING", "PROMISC", "SIMPLEX", "MULTICAST"], :mtu=>"1500", :inet6=>["fe80::fce1:baff:fed0:7c4d/64", "2001:1234:abcd:0:1::/80", "fc04::/64"], :inet=>"10.0.31.238/255.255.255.240"}, :bridge0=>{:flags=>["UP", "RUNNING"]}, :pflog0=>{:flags=>["UP", "RUNNING", "PROMISC"], :mtu=>"33144"}, :bridge1=>{:flags=>["UP", "RUNNING"]}, :vlan88=>{:flags=>["UP", "BROADCAST", "RUNNING", "SIMPLEX", "MULTICAST"], :mtu=>"1500", :inet6=>["fe80::fce1:baff:fed1:1338/64", "fc05::/64"]}, :vether1=>{:flags=>["UP", "BROADCAST", "RUNNING", "SIMPLEX", "MULTICAST"], :mtu=>"1500"}} + wanted = { lo0: { flags: %w(UP LOOPBACK RUNNING MULTICAST), mtu: '32768', inet6: ['fe80::1/64', '::1/128'], inet: '127.0.0.1/255.0.0.0' }, em0: { flags: %w(UP BROADCAST RUNNING SIMPLEX MULTICAST), mtu: '1500', inet: '10.0.31.2/255.255.255.252', inet6: ['fe80::200:24ff:fed0:6404/64', '2001:1234:abcd:f::10/80'] }, em1: { flags: %w(BROADCAST SIMPLEX MULTICAST), mtu: '1500' }, em2: { flags: %w(BROADCAST SIMPLEX MULTICAST), mtu: '1500' }, em3: { flags: %w(BROADCAST SIMPLEX MULTICAST), mtu: '1500' }, em4: { flags: %w(UP BROADCAST RUNNING PROMISC ALLMULTI SIMPLEX MULTICAST), mtu: '1500' }, em5: { flags: %w(UP BROADCAST RUNNING PROMISC ALLMULTI SIMPLEX MULTICAST), mtu: '1500' }, em6: { flags: %w(UP BROADCAST RUNNING PROMISC ALLMULTI SIMPLEX MULTICAST), mtu: '1500' }, em7: { flags: %w(UP BROADCAST RUNNING PROMISC ALLMULTI SIMPLEX MULTICAST), mtu: '1500' }, vether0: { flags: %w(UP BROADCAST RUNNING PROMISC SIMPLEX MULTICAST), mtu: '1500', inet6: ['fe80::fce1:baff:fed0:7c4d/64', '2001:1234:abcd:0:1::/80', 'fc04::/64'], inet: '10.0.31.238/255.255.255.240' }, bridge0: { flags: %w(UP RUNNING) }, pflog0: { flags: %w(UP RUNNING PROMISC), mtu: '33144' }, bridge1: { flags: %w(UP RUNNING) }, vlan88: { flags: %w(UP BROADCAST RUNNING SIMPLEX MULTICAST), mtu: '1500', inet6: ['fe80::fce1:baff:fed1:1338/64', 'fc05::/64'] }, vether1: { flags: %w(UP BROADCAST RUNNING SIMPLEX MULTICAST), mtu: '1500' } } expect(PuppetX::BSD::Ifconfig.new(output).parse).to eq(wanted) end end context '#interfaces' do - it "should return the interface list " do - output = File.read("spec/fixtures/ifconfig_openbsd.full") + it 'returns the interface list' do + output = File.read('spec/fixtures/ifconfig_openbsd.full') - should = [ "lo0", "em0", "em1", "em2", "em3", "em4", "em5", "em6", - "em7", "enc0", "vether0", "bridge0", "pflog0", "bridge1", - "vlan88", "vether1" ] + should = %w(lo0 em0 em1 em2 em3 em4 em5 em6 + em7 enc0 vether0 bridge0 pflog0 bridge1 + vlan88 vether1) expect(PuppetX::BSD::Ifconfig.new(output).interfaces).to eq(should) end end end - context "on FreeBSD" do + context 'on FreeBSD' do context '#parse' do - it "should return the desired hash for a single interface" do - output = File.read("spec/fixtures/ifconfig_freebsd.em.up") + it 'returns the desired hash for a single interface' do + output = File.read('spec/fixtures/ifconfig_freebsd.em.up') - wanted = {:em0=>{:flags=>["UP", "BROADCAST", "RUNNING", "SIMPLEX", "MULTICAST"], :metric=>"0", :mtu=>"9000", :inet=>"10.0.0.10/255.255.255.0", :inet6=>["fe80::225:9999:ffff:ac26/64", "2fff:fff:ffff:1ab::10:10/64"]}} + wanted = { em0: { flags: %w(UP BROADCAST RUNNING SIMPLEX MULTICAST), metric: '0', mtu: '9000', inet: '10.0.0.10/255.255.255.0', inet6: ['fe80::225:9999:ffff:ac26/64', '2fff:fff:ffff:1ab::10:10/64'] } } expect(PuppetX::BSD::Ifconfig.new(output).parse).to eq(wanted) end - it "should return the desired hash for a full example" do - output = File.read("spec/fixtures/ifconfig_freebsd.full") + it 'returns the desired hash for a full example' do + output = File.read('spec/fixtures/ifconfig_freebsd.full') - wanted = { :igb0 => {:flags=>["UP", "BROADCAST", "RUNNING", - "SIMPLEX", "MULTICAST"], - :metric=>"0", :mtu=>"1500", - :inet=>["10.0.0.21/255.255.255.0", - "10.0.0.124/255.255.255.255", - "10.0.0.125/255.255.255.255"], - :inet6=>["fe80::225:90ff:fe5c:f7cc/64", - "2fff:fff:ffff::100/64", - "2fff:fff:ffff::103/128", - "2fff:fff:ffff::106/128", - "2fff:fff:ffff::5/128", - "2fff:fff:ffff::105/128", - "2fff:fff:ffff::109/128", - "2fff:fff:ffff::7/128"] - }, :igb1 => {:flags=>["BROADCAST", "OACTIVE", "SIMPLEX", "MULTICAST"], - :metric=>"0", :mtu=>"1500" }, :lo0 => {:flags=>["UP", - "LOOPBACK", - "RUNNING", - "MULTICAST"], - :metric=>"0", - :mtu=>"16384", - :inet6=>["::1/128", - "fe80::1/64"], - :inet=>"127.0.0.1/255.0.0.0" - }, } + wanted = { igb0: { flags: %w(UP BROADCAST RUNNING + SIMPLEX MULTICAST), + metric: '0', mtu: '1500', + inet: ['10.0.0.21/255.255.255.0', + '10.0.0.124/255.255.255.255', + '10.0.0.125/255.255.255.255'], + inet6: ['fe80::225:90ff:fe5c:f7cc/64', + '2fff:fff:ffff::100/64', + '2fff:fff:ffff::103/128', + '2fff:fff:ffff::106/128', + '2fff:fff:ffff::5/128', + '2fff:fff:ffff::105/128', + '2fff:fff:ffff::109/128', + '2fff:fff:ffff::7/128'] }, igb1: { flags: %w(BROADCAST OACTIVE SIMPLEX MULTICAST), + metric: '0', mtu: '1500' }, lo0: { flags: %w(UP + LOOPBACK + RUNNING + MULTICAST), + metric: '0', + mtu: '16384', + inet6: ['::1/128', + 'fe80::1/64'], + inet: '127.0.0.1/255.0.0.0' } } expect(PuppetX::BSD::Ifconfig.new(output).parse).to eq(wanted) end - end end end diff --git a/spec/unit/bsd/puppet_interface_spec.rb b/spec/unit/bsd/puppet_interface_spec.rb index f6583f3..66df9d0 100644 --- a/spec/unit/bsd/puppet_interface_spec.rb +++ b/spec/unit/bsd/puppet_interface_spec.rb @@ -1,65 +1,63 @@ require 'spec_helper' require 'puppet_x/bsd/puppet_interface' - describe 'PuppetX::BSD::PuppetInterface' do - let(:demo_class) { + let(:demo_class) do class DemoClass < PuppetX::BSD::PuppetInterface super options :one, :two, :three validation :name end - } + end context 'configure' do - it 'should fail validation when an array is received' do + it 'fails validation when an array is received' do c = PuppetX::BSD::PuppetInterface.new - expect{ c.configure([]) }.to raise_error(ArgumentError, /must be a Hash/) + expect { c.configure([]) }.to raise_error(ArgumentError, %r{must be a Hash}) end - it 'should not fail when no options or validation is passed' do + it 'does not fail when no options or validation is passed' do c = PuppetX::BSD::PuppetInterface.new - expect{ c.configure({}) }.to_not raise_error + expect { c.configure({}) }.not_to raise_error end context 'when options are available' do - it 'should return a boring yet valid config' do + it 'returns a boring yet valid config' do c = PuppetX::BSD::PuppetInterface.new c.options :one, :two, :three - expect{ c.configure({}) }.to_not raise_error + expect { c.configure({}) }.not_to raise_error end - end context 'when validation is required but not present' do - it 'should fail with an ArgumentError' do + it 'fails with an ArgumentError' do c = PuppetX::BSD::PuppetInterface.new c.validation :one, :two, :three - expect{ c.configure({}) }.to raise_error(ArgumentError, /required configuration item not found/) + expect { c.configure({}) }.to raise_error(ArgumentError, %r{required configuration item not found}) end end context 'when validation is required and present' do - it 'should configure successfully' do + it 'configures successfully' do c = PuppetX::BSD::PuppetInterface.new c.validation :one, :two, :three wanted = { one: 'itemone', two: 'itemtwo', - three: 'itemthree', + three: 'itemthree' } - expect{ c.configure(wanted) }.to_not raise_error + expect { c.configure(wanted) }.not_to raise_error expect(c.config).to eq(wanted) end end context 'when validation is required and present with options' do - it 'should configure successfully with no options passed' do + it 'configures successfully with no options passed' do c = PuppetX::BSD::PuppetInterface.new c.validation :one, :two, :three c.options :four, :five @@ -67,14 +65,14 @@ describe 'PuppetX::BSD::PuppetInterface' do config = { one: 'itemone', two: 'itemtwo', - three: 'itemthree', + three: 'itemthree' } - expect{ c.configure(config) }.to_not raise_error + expect { c.configure(config) }.not_to raise_error expect(c.config).to eq(config) end - it 'should include options in the config when options are passed' do + it 'includes options in the config when options are passed' do c = PuppetX::BSD::PuppetInterface.new c.validation :one, :two, :three c.options :four, :five @@ -83,16 +81,16 @@ describe 'PuppetX::BSD::PuppetInterface' do one: 'itemone', two: 'itemtwo', three: 'itemthree', - five: 'itemfive', + five: 'itemfive' } - expect{ c.configure(config) }.to_not raise_error + expect { c.configure(config) }.not_to raise_error expect(c.config).to eq(config) end end context 'when mutliopts is set' do - it 'should fail when option values are not an array' do + it 'fails when option values are not an array' do c = PuppetX::BSD::PuppetInterface.new c.options :one, :two c.multiopts :one @@ -100,32 +98,32 @@ describe 'PuppetX::BSD::PuppetInterface' do config = { one: 'string' } - expect{ c.configure(config) }.to raise_error(ArgumentError, /Multi-opt one is not an array/) + expect { c.configure(config) }.to raise_error(ArgumentError, %r{Multi-opt one is not an array}) end - it 'should configure when option values are an array' do + it 'configures when option values are an array' do c = PuppetX::BSD::PuppetInterface.new c.options :one, :two c.multiopts :one config = { - one: ['string', 'stringagain'] + one: %w(string stringagain) } - expect{ c.configure(config) }.to_not raise_error + expect { c.configure(config) }.not_to raise_error end end context 'oneof' do - it 'should fail when oneof config values are not present' do + it 'fails when oneof config values are not present' do c = PuppetX::BSD::PuppetInterface.new c.options :one, :two, :three c.oneof :one, :two config = {} - expect{ c.configure(config) }.to raise_error(ArgumentError, /At least one of.*is required/) + expect { c.configure(config) }.to raise_error(ArgumentError, %r{At least one of.*is required}) end - it 'should configure when one oneof config value is present' do + it 'configures when one oneof config value is present' do c = PuppetX::BSD::PuppetInterface.new c.options :one, :two, :three c.oneof :one, :two @@ -133,10 +131,8 @@ describe 'PuppetX::BSD::PuppetInterface' do config = { one: 'string' } - expect{ c.configure(config) }.to_not raise_error + expect { c.configure(config) }.not_to raise_error end end - end end - diff --git a/spec/unit/bsd/rc_conf/vlan_spec.rb b/spec/unit/bsd/rc_conf/vlan_spec.rb index 6ae0ab7..b5e3d74 100644 --- a/spec/unit/bsd/rc_conf/vlan_spec.rb +++ b/spec/unit/bsd/rc_conf/vlan_spec.rb @@ -1,96 +1,95 @@ require 'puppet_x/bsd/rc_conf/vlan' - describe 'Vlan' do subject(:vlan) { Vlan } describe 'validation' do context 'when the config is invalid' do - it 'should fail if no config is supplied' do + it 'fails if no config is supplied' do c = {} - expect { + expect do vlan.new(c).content - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end - it "should raise an error if device is missing" do + it 'raises an error if device is missing' do c = { - :id => 1, + id: 1 } - expect { + expect do vlan.new(c).content - }.to raise_error(ArgumentError, /required configuration item not found: device/) + end.to raise_error(ArgumentError, %r{required configuration item not found: device}) end - it "should not raise an error if address is missing" do + it 'does not raise an error if address is missing' do c = { - :id => 1, - :device => 'em0', + id: 1, + device: 'em0' } - expect { + expect do vlan.new(c).content - }.not_to raise_error + end.not_to raise_error end - it "should not raise an error if address is an empty array" do + it 'does not raise an error if address is an empty array' do c = { - :id => 1, - :device => 'em0', - :address => [], + id: 1, + device: 'em0', + address: [] } - expect { + expect do vlan.new(c).content - }.not_to raise_error + end.not_to raise_error end - it "should not raise an error if address is present" do + it 'does not raise an error if address is present' do c = { - :id => 1, - :device => 'em0', - :address => ['10.0.0.0/24'], + id: 1, + device: 'em0', + address: ['10.0.0.0/24'] } - expect { + expect do vlan.new(c).content - }.not_to raise_error + end.not_to raise_error end - it "should raise an error when an invalid option is received" do + it 'raises an error when an invalid option is received' do c = { - :id => 1, - :device => 'em0', - :address => ['10.0.0.0/24'], - :random => '1', + id: 1, + device: 'em0', + address: ['10.0.0.0/24'], + random: '1' } - expect { + expect do vlan.new(c).content - }.to raise_error(ArgumentError, /unknown configuration item/) + end.to raise_error(ArgumentError, %r{unknown configuration item}) end end end describe '#content' do context 'when only a device and a vlan are supplied' do - it 'should return the ifconfig string' do + it 'returns the ifconfig string' do c = { - :id => 1, - :device => 'em0', + id: 1, + device: 'em0' } wanted = [ - 'vlan 1 vlandev em0', + 'vlan 1 vlandev em0' ] expect(vlan.new(c).content).to match(wanted.join('\n')) end end context 'when a single address is passed' do - it 'should return only the vlan string' do + it 'returns only the vlan string' do c = { - :id => 1, - :device => 'em0', - :address => ['10.0.0.1/24'], + id: 1, + device: 'em0', + address: ['10.0.0.1/24'] } wanted = [ - 'vlan 1 vlandev em0', + 'vlan 1 vlandev em0' ] expect(vlan.new(c).content).to match(wanted.join('\n')) end diff --git a/spec/unit/bsd/rc_conf_spec.rb b/spec/unit/bsd/rc_conf_spec.rb index 9b071b4..8a10ce1 100644 --- a/spec/unit/bsd/rc_conf_spec.rb +++ b/spec/unit/bsd/rc_conf_spec.rb @@ -5,78 +5,79 @@ describe 'Rc_conf' do describe 'initialize' do context 'when minimal configuration is passed' do - it 'should not error' do - expect { rc.new({name: 'em0'}) }.to_not raise_error + it 'does not error' do + expect { rc.new(name: 'em0') }.not_to raise_error end end - end describe '#get_hash' do context 'with a dynamic v4-only config' do - it "should return a valid config" do + it 'returns a valid config' do hash = { - :re0 => { - :addrs => [ - 'DHCP', - ], + re0: { + addrs: [ + 'DHCP' + ] } } c = { - :name => 're0', - :addresses => [ + name: 're0', + addresses: [ 'dhcp' ] } expect(rc.new(c).get_hash).to eq(hash) end - context "when an empty address set is passed" do - it "should return useless hash" do + context 'when an empty address set is passed' do + it 'returns useless hash' do hash = { - :re0=>{} + re0: {} } c = { - :name => 're0', - :addresses => [], + name: 're0', + addresses: [] } expect(rc.new(c).get_hash).to eq(hash) end end - context "when a single address is passed" do - it "should return a correctly formatted hash" do + context 'when a single address is passed' do + it 'returns a correctly formatted hash' do hash = { - :re0=>{:addrs=>["inet 10.0.0.1/24"]} + re0: { addrs: ['inet 10.0.0.1/24'] } } c = { - :name => 're0', - :addresses => [ + name: 're0', + addresses: [ '10.0.0.1/24' - ], + ] } expect(rc.new(c).get_hash).to eq(hash) end end - context "when multiple addresses are passed" do - it "should return a correctly formatted hash" do + context 'when multiple addresses are passed' do + it 'returns a correctly formatted hash' do hash = { - :re0 => { - :addrs=>["inet 10.0.0.1/24"], - :aliases=>[ - "inet 10.0.0.2/24", - "inet 10.0.0.3/24"]} + re0: { + addrs: ['inet 10.0.0.1/24'], + aliases: [ + 'inet 10.0.0.2/24', + 'inet 10.0.0.3/24' + ] + } } c = { - :name => 're0', - :addresses => [ + name: 're0', + addresses: [ '10.0.0.1/24', '10.0.0.2/24', '10.0.0.3/24' - ], + ] } expect(rc.new(c).get_hash).to eq(hash) @@ -85,35 +86,34 @@ describe 'Rc_conf' do end context 'when a full config is supplied' do - it 'should return the desired hash' do - + it 'returns the desired hash' do hash = { - :re0 => { - :addrs => [ - "inet 10.0.1.12/24 mtu 9000", - "inet6 fc00::123/64", - ], - :aliases => [ - "inet 10.0.1.13/24", - "inet 10.0.1.14/24", - "inet6 fc00::124/64", - "inet6 fc00::125/64", + re0: { + addrs: [ + 'inet 10.0.1.12/24 mtu 9000', + 'inet6 fc00::123/64' ], + aliases: [ + 'inet 10.0.1.13/24', + 'inet 10.0.1.14/24', + 'inet6 fc00::124/64', + 'inet6 fc00::125/64' + ] } } c = { - :name => 're0', - :desc => "Uplink", - :addresses => [ + name: 're0', + desc: 'Uplink', + addresses: [ '10.0.1.12/24', '10.0.1.13/24', '10.0.1.14/24', 'fc00::123/64', 'fc00::124/64', - 'fc00::125/64', + 'fc00::125/64' ], - :mtu => 9000, + mtu: 9000 } expect(rc.new(c).get_hash).to eq(hash) end @@ -122,54 +122,53 @@ describe 'Rc_conf' do describe '#to_create_resources' do context 'when only mtu is spplied' do - it { + it do hash = { 'ifconfig_re0' => { - 'value' => 'mtu 9000', - }, + 'value' => 'mtu 9000' + } } c = { - :name => 're0', - :mtu => 9000, + name: 're0', + mtu: 9000 } expect(rc.new(c).to_create_resources).to eq(hash) - } + end end - context 'when a full interface config is supplied' do - it 'should convert the hash for create_resources()' do + it 'converts the hash for create_resources()' do hash = { 'ifconfig_re0' => { - 'value' => 'inet 10.0.1.12/24 mtu 9000', + 'value' => 'inet 10.0.1.12/24 mtu 9000' }, 'ifconfig_re0_alias0' => { - 'value' => 'inet 10.0.1.13/24', + 'value' => 'inet 10.0.1.13/24' }, 'ifconfig_re0_alias1' => { - 'value' => 'inet 10.0.1.14/24', + 'value' => 'inet 10.0.1.14/24' }, 'ifconfig_re0_ipv6' => { - 'value' => 'inet6 fc00::123/64', + 'value' => 'inet6 fc00::123/64' }, 'ifconfig_re0_alias2' => { - 'value' => 'inet6 fc00::124/64', - }, + 'value' => 'inet6 fc00::124/64' + } } c = { - :name => 're0', - :desc => "Uplink", - :addresses => [ + name: 're0', + desc: 'Uplink', + addresses: [ '10.0.1.12/24', '10.0.1.13/24', '10.0.1.14/24', 'fc00::123/64', - 'fc00::124/64', + 'fc00::124/64' ], - :options => [ - 'mtu 9000', + options: [ + 'mtu 9000' ] } expect(rc.new(c).to_create_resources).to eq(hash) @@ -177,19 +176,19 @@ describe 'Rc_conf' do end context 'when only a vlan configuration is supplied' do - it 'should convert the hash for create_resources()' do + it 'converts the hash for create_resources()' do hash = { 'ifconfig_vlan100' => { - 'value' => 'vlan 100 vlandev re0', + 'value' => 'vlan 100 vlandev re0' } } c = { - :name => 'vlan100', - :desc => "Uplink", - :options => [ + name: 'vlan100', + desc: 'Uplink', + options: [ 'vlan 100', - 'vlandev re0', + 'vlandev re0' ] } expect(rc.new(c).to_create_resources).to eq(hash) @@ -197,15 +196,15 @@ describe 'Rc_conf' do end end - describe "#options_string" do - context "when options are supplied" do - it "should return the formatted string of options" do + describe '#options_string' do + context 'when options are supplied' do + it 'returns the formatted string of options' do wanted = 'vlan 100 vlandev re0' c = { - :name => 'vlan100', - :options => [ + name: 'vlan100', + options: [ 'vlan 100', - 'vlandev re0', + 'vlandev re0' ] } expect(rc.new(c).options_string).to eq(wanted) diff --git a/spec/unit/bsd/util_spec.rb b/spec/unit/bsd/util_spec.rb index 08c94a8..9e87b2d 100644 --- a/spec/unit/bsd/util_spec.rb +++ b/spec/unit/bsd/util_spec.rb @@ -3,51 +3,49 @@ require 'puppet_x/bsd/util' describe 'PuppetX::BSD::Util' do context '#uber_merge' do + it 'combinds simple hashes' do + h1 = { one: 1 } + h2 = { two: 2 } - it 'should combind simple hashes' do - h1 = {:one => 1} - h2 = {:two => 2} - - wanted = {:one => 1, :two => 2} + wanted = { one: 1, two: 2 } expect(PuppetX::BSD::Util.uber_merge(h1, h2)).to eq(wanted) end - it 'should combine nested hashses' do - h1 = {:one => 1} - h2 = {:two => 2} + it 'combines nested hashses' do + h1 = { one: 1 } + h2 = { two: 2 } - wanted = {:one => 1, :two => 2} + wanted = { one: 1, two: 2 } expect(PuppetX::BSD::Util.uber_merge(h1, h2)).to eq(wanted) end - it 'should handle an empty initial hash' do + it 'handles an empty initial hash' do h1 = {} - h2 = {:one => 1} + h2 = { one: 1 } - wanted = {:one => 1} + wanted = { one: 1 } expect(PuppetX::BSD::Util.uber_merge(h1, h2)).to eq(wanted) end - it 'should handle an initial hash with an array for value' do - h1 = {:one => ['a', 'b']} - h2 = {:two => {'eh' => 'a', 'bee' => 'b'}} + it 'handles an initial hash with an array for value' do + h1 = { one: %w(a b) } + h2 = { two: { 'eh' => 'a', 'bee' => 'b' } } - wanted = {:one => ['a', 'b'],:two => {'eh' => 'a', 'bee' => 'b' }} + wanted = { one: %w(a b), two: { 'eh' => 'a', 'bee' => 'b' } } expect(PuppetX::BSD::Util.uber_merge(h1, h2)).to eq(wanted) end - it 'Should combine values into an array' do - h1 = {:root => {:sub => 1}} - h2 = {:root => {:sub => 2}} + it 'combines values into an array' do + h1 = { root: { sub: 1 } } + h2 = { root: { sub: 2 } } - wanted = {:root => {:sub => [1,2]}} + wanted = { root: { sub: [1, 2] } } expect(PuppetX::BSD::Util.uber_merge(h1, h2)).to eq(wanted) end - end end diff --git a/spec/unit/puppet/provider/bsd_interface/ifconfig_spec.rb b/spec/unit/puppet/provider/bsd_interface/ifconfig_spec.rb index e50cda5..3025034 100644 --- a/spec/unit/puppet/provider/bsd_interface/ifconfig_spec.rb +++ b/spec/unit/puppet/provider/bsd_interface/ifconfig_spec.rb @@ -6,52 +6,54 @@ describe Puppet::Type.type(:bsd_interface).provider(:ifconfig) do let(:em_interface) do Puppet::Type.type(:bsd_interface).new( - :name => 'em0', - :provider => em_provider) + name: 'em0', + provider: em_provider + ) end - let(:em_provider) { described_class.new(:name => 'em0') } + let(:em_provider) { described_class.new(name: 'em0') } let(:vlan_interface) do Puppet::Type.type(:bsd_interface).new( - :name => 'vlan0', - :provider => vlan_provider) + name: 'vlan0', + provider: vlan_provider + ) end - let(:vlan_provider) { described_class.new(:name => 'vlan0') } + let(:vlan_provider) { described_class.new(name: 'vlan0') } - context "#instances" do - let(:output) { File.read("spec/fixtures/ifconfig_openbsd.full") } + context '#instances' do + let(:output) { File.read('spec/fixtures/ifconfig_openbsd.full') } before do - expect(described_class).to receive(:execute).with(['/sbin/ifconfig', '-C'], {:failonfail=>false, :combine=>true}) { 'vlan pflog' } - expect(described_class).to receive(:execute).with(['/sbin/ifconfig'], {:failonfail=>false, :combine=>true}) { output } + expect(described_class).to receive(:execute).with(['/sbin/ifconfig', '-C'], failonfail: false, combine: true) { 'vlan pflog' } + expect(described_class).to receive(:execute).with(['/sbin/ifconfig'], failonfail: false, combine: true) { output } end - it 'should return some instances' do + it 'returns some instances' do expect(described_class.instances.size).to eq(15) end - it "should return an array of interfaces" do + it 'returns an array of interfaces' do expect(described_class.instances.class).to be(Array) end - it 'should return the resource dc=bar,dc=com' do - expect(described_class.instances[1].instance_variable_get("@property_hash")).to eq( - {:ensure => :present, :provider=>:bsd_interface, :name=>"em0", :flags=>["UP", "BROADCAST", "RUNNING", "SIMPLEX", "MULTICAST"], :mtu=>1500, :destroyable=>:false, :state => :up} + it 'returns the resource dc=bar,dc=com' do + expect(described_class.instances[1].instance_variable_get('@property_hash')).to eq( + ensure: :present, provider: :bsd_interface, name: 'em0', flags: %w(UP BROADCAST RUNNING SIMPLEX MULTICAST), mtu: 1500, destroyable: :false, state: :up ) end - it "should return all interfaces names" do - expect(described_class.instances.map(&:name).sort).to eq(["bridge0", "bridge1", "em0", "em1", "em2", "em3", "em4", "em5", "em6", "em7", "lo0", "pflog0", "vether0", "vether1", "vlan88"]) + it 'returns all interfaces names' do + expect(described_class.instances.map(&:name).sort).to eq(%w(bridge0 bridge1 em0 em1 em2 em3 em4 em5 em6 em7 lo0 pflog0 vether0 vether1 vlan88)) end end - [:up, :down, :create, :destroy].each {|m| it { should respond_to(m) } } + [:up, :down, :create, :destroy].each { |m| it { is_expected.to respond_to(m) } } - context "#flush" do - states = ['up','absent','down'] - ensure_states = ['present','up','absent','down'] - if_types = ['pseudo', 'real'] - platforms = ['OpenBSD','FreeBSD'] + context '#flush' do + states = %w(up absent down) + ensure_states = %w(present up absent down) + if_types = %w(pseudo real) + platforms = %w(OpenBSD FreeBSD) platforms.each do |platform| context "on #{platform}" do states.each do |state| @@ -72,38 +74,42 @@ describe Puppet::Type.type(:bsd_interface).provider(:ifconfig) do let(:info) { File.read(ifconfig_fixture) } case state - when 'present','down','up' - it 'should return a single instance' do - expect(described_class).to receive(:execute).with(['/sbin/ifconfig', '-C'], {:failonfail=>false, :combine=>true}) { 'vlan pflog' } - expect(described_class).to receive(:execute).with(['/sbin/ifconfig'], {:failonfail=>false, :combine=>true}) { info } + when 'present', 'down', 'up' + it 'returns a single instance' do + expect(described_class).to receive(:execute).with(['/sbin/ifconfig', '-C'], failonfail: false, combine: true) { 'vlan pflog' } + expect(described_class).to receive(:execute).with(['/sbin/ifconfig'], failonfail: false, combine: true) { info } expect(described_class.instances.size).to eq(1) end when 'absent' - it 'should return zero instances' do - expect(described_class).to receive(:execute).with(['/sbin/ifconfig', '-C'], {:failonfail=>false, :combine=>true}) { 'vlan pflog' } - expect(described_class).to receive(:execute).with(['/sbin/ifconfig'], {:failonfail=>false, :combine=>true}) { info } + it 'returns zero instances' do + expect(described_class).to receive(:execute).with(['/sbin/ifconfig', '-C'], failonfail: false, combine: true) { 'vlan pflog' } + expect(described_class).to receive(:execute).with(['/sbin/ifconfig'], failonfail: false, combine: true) { info } expect(described_class.instances.size).to eq(0) end end ensure_states.each do |ensure_state| context "when ensure is #{ensure_state}" do - let!(:provider) { described_class.new( - :name => ifname, - :ensure => ensure_state - ) } + let!(:provider) do + described_class.new( + name: ifname, + ensure: ensure_state + ) + end - let!(:interface) { Puppet::Type.type(:bsd_interface).new( - :name => ifname, - :provider => provider, - :ensure => state, - ) } + let!(:interface) do + Puppet::Type.type(:bsd_interface).new( + name: ifname, + provider: provider, + ensure: state + ) + end # We only call instances on these states, which we expect to call ifconfig twice. - if ['present', 'up', 'down'].include? state + if %w(present up down).include? state before do - expect(described_class).to receive(:execute).with(['/sbin/ifconfig', '-C'], {:failonfail=>false, :combine=>true}) { 'vlan pflog' } - expect(described_class).to receive(:execute).with(['/sbin/ifconfig'], {:failonfail=>false, :combine=>true}) { info } + expect(described_class).to receive(:execute).with(['/sbin/ifconfig', '-C'], failonfail: false, combine: true) { 'vlan pflog' } + expect(described_class).to receive(:execute).with(['/sbin/ifconfig'], failonfail: false, combine: true) { info } end end @@ -118,9 +124,9 @@ describe Puppet::Type.type(:bsd_interface).provider(:ifconfig) do it 'leave the interface untouched' do i = described_class.instances[0] if if_type == 'pseudo' - expect(i).to_not receive(:execute).with(['/sbin/ifconfig', ifname, 'create'], {:failonfail=>false, :combine=>true}) + expect(i).not_to receive(:execute).with(['/sbin/ifconfig', ifname, 'create'], failonfail: false, combine: true) end - expect(i).to_not receive(:execute).with(['/sbin/ifconfig', ifname, 'up'], {:failonfail=>false, :combine=>true}) + expect(i).not_to receive(:execute).with(['/sbin/ifconfig', ifname, 'up'], failonfail: false, combine: true) i.up i.flush end @@ -128,29 +134,29 @@ describe Puppet::Type.type(:bsd_interface).provider(:ifconfig) do it 'leave the interface untouched' do i = described_class.instances[0] if if_type == 'pseudo' - expect(i).to_not receive(:execute).with(['/sbin/ifconfig', ifname, 'create'], {:failonfail=>false, :combine=>true}) + expect(i).not_to receive(:execute).with(['/sbin/ifconfig', ifname, 'create'], failonfail: false, combine: true) end - expect(i).to_not receive(:execute).with(['/sbin/ifconfig', ifname, 'up'], {:failonfail=>false, :combine=>true}) + expect(i).not_to receive(:execute).with(['/sbin/ifconfig', ifname, 'up'], failonfail: false, combine: true) i.flush end when 'down' - it 'should bring the interface down' do + it 'brings the interface down' do i = described_class.instances[0] if if_type == 'pseudo' - expect(i).to_not receive(:execute).with(['/sbin/ifconfig', ifname, 'create'], {:failonfail=>false, :combine=>true}) - expect(i).to_not receive(:execute).with(['/sbin/ifconfig', ifname, 'destroy'], {:failonfail=>false, :combine=>true}) + expect(i).not_to receive(:execute).with(['/sbin/ifconfig', ifname, 'create'], failonfail: false, combine: true) + expect(i).not_to receive(:execute).with(['/sbin/ifconfig', ifname, 'destroy'], failonfail: false, combine: true) end - expect(i).to receive(:execute).with(['/sbin/ifconfig', ifname, 'down'], {:failonfail=>false, :combine=>true}) + expect(i).to receive(:execute).with(['/sbin/ifconfig', ifname, 'down'], failonfail: false, combine: true) i.down i.flush end when 'absent' - it 'should bring down and destroy the interface when necessary' do + it 'brings down and destroy the interface when necessary' do i = described_class.instances[0] - expect(i).to receive(:execute).with(['/sbin/ifconfig', ifname, 'down'], {:failonfail=>false, :combine=>true}) + expect(i).to receive(:execute).with(['/sbin/ifconfig', ifname, 'down'], failonfail: false, combine: true) if if_type == 'pseudo' - expect(i).to_not receive(:execute).with(['/sbin/ifconfig', ifname, 'create'], {:failonfail=>false, :combine=>true}) - expect(i).to receive(:execute).with(['/sbin/ifconfig', ifname, 'destroy'], {:failonfail=>false, :combine=>true}) + expect(i).not_to receive(:execute).with(['/sbin/ifconfig', ifname, 'create'], failonfail: false, combine: true) + expect(i).to receive(:execute).with(['/sbin/ifconfig', ifname, 'destroy'], failonfail: false, combine: true) end i.destroy i.flush @@ -164,10 +170,10 @@ describe Puppet::Type.type(:bsd_interface).provider(:ifconfig) do case ensure_state when 'up' - it 'should bring up the interface' do + it 'brings up the interface' do i = described_class.instances[0] i.up - expect(i).to receive(:execute).with(['/sbin/ifconfig', ifname, 'up'], {:failonfail=>false, :combine=>true}) + expect(i).to receive(:execute).with(['/sbin/ifconfig', ifname, 'up'], failonfail: false, combine: true) i.flush end when 'present' @@ -175,13 +181,12 @@ describe Puppet::Type.type(:bsd_interface).provider(:ifconfig) do when 'absent' end when 'absent' - it 'should be absent' do + it 'is absent' do expect(provider.state).to eq(:absent) end end end end - end end end @@ -189,5 +194,4 @@ describe Puppet::Type.type(:bsd_interface).provider(:ifconfig) do end end end - end diff --git a/spec/unit/puppet/type/bsd_interface_spec.rb b/spec/unit/puppet/type/bsd_interface_spec.rb index 3cfc175..0fff848 100644 --- a/spec/unit/puppet/type/bsd_interface_spec.rb +++ b/spec/unit/puppet/type/bsd_interface_spec.rb @@ -1,24 +1,23 @@ require 'spec_helper' -#require 'puppet/provider/bsd_interface/ifconfig' +# require 'puppet/provider/bsd_interface/ifconfig' type_class = Puppet::Type.type(:bsd_interface) describe type_class do - [:absent, :present].each do |v| it "should support #{v} as a value to :ensure" do - em = type_class.new(:name => 'em0', :ensure => v) + em = type_class.new(name: 'em0', ensure: v) expect(em.should(:ensure)).to eq(v) end end - it "should alias :up to :present as a value to :ensure" do - em = type_class.new(:name => 'em0', :ensure => :up) + it 'aliases :up to :present as a value to :ensure' do + em = type_class.new(name: 'em0', ensure: :up) expect(em.should(:ensure)).to eq(:present) end - it "should alias :down to :absent as a value to :ensure" do - em = type_class.new(:name => 'em0', :ensure => :down) + it 'aliases :down to :absent as a value to :ensure' do + em = type_class.new(name: 'em0', ensure: :down) expect(em.should(:ensure)).to eq(:absent) end end