diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/functions/deprecation_spec.rb | 4 | ||||
-rwxr-xr-x | spec/functions/is_array_spec.rb | 22 | ||||
-rwxr-xr-x | spec/functions/is_bool_spec.rb | 23 | ||||
-rwxr-xr-x | spec/functions/is_float_spec.rb | 25 | ||||
-rwxr-xr-x | spec/functions/is_integer_spec.rb | 27 | ||||
-rwxr-xr-x | spec/functions/is_ip_address_spec.rb | 20 | ||||
-rw-r--r-- | spec/functions/is_ipv4_address_spec.rb | 21 | ||||
-rw-r--r-- | spec/functions/is_ipv6_address_spec.rb | 21 | ||||
-rwxr-xr-x | spec/functions/is_numeric_spec.rb | 25 | ||||
-rwxr-xr-x | spec/functions/is_string_spec.rb | 24 | ||||
-rwxr-xr-x | spec/functions/validate_absolute_path_spec.rb | 5 | ||||
-rwxr-xr-x | spec/functions/validate_array_spec.rb | 5 | ||||
-rwxr-xr-x | spec/functions/validate_bool_spec.rb | 5 | ||||
-rwxr-xr-x | spec/functions/validate_integer_spec.rb | 5 | ||||
-rw-r--r-- | spec/functions/validate_ip_address_spec.rb | 21 | ||||
-rwxr-xr-x | spec/functions/validate_ipv4_address_spec.rb | 73 | ||||
-rwxr-xr-x | spec/functions/validate_ipv6_address_spec.rb | 62 | ||||
-rwxr-xr-x | spec/functions/validate_numeric_spec.rb | 5 | ||||
-rwxr-xr-x | spec/functions/validate_re_spec.rb | 5 | ||||
-rwxr-xr-x | spec/functions/validate_string_spec.rb | 5 |
20 files changed, 300 insertions, 103 deletions
diff --git a/spec/functions/deprecation_spec.rb b/spec/functions/deprecation_spec.rb index c213190..4321c3d 100644 --- a/spec/functions/deprecation_spec.rb +++ b/spec/functions/deprecation_spec.rb @@ -42,6 +42,10 @@ if Puppet.version.to_f >= 4.0 end else describe 'deprecation' do + after(:context) do + ENV.delete('STDLIB_LOG_DEPRECATIONS') + end + ENV['STDLIB_LOG_DEPRECATIONS'] = "true" it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } diff --git a/spec/functions/is_array_spec.rb b/spec/functions/is_array_spec.rb index 0a8070b..2350b7f 100755 --- a/spec/functions/is_array_spec.rb +++ b/spec/functions/is_array_spec.rb @@ -1,12 +1,8 @@ require 'spec_helper' describe 'is_array' do + it { is_expected.not_to eq(nil) } - # Checking for deprecation warning - it 'should display a single deprecation' do - scope.expects(:warning).with(includes('This method is deprecated')) - is_expected.to run.with_params([]) - end it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } it { pending("Current implementation ignores parameters after the first.") @@ -21,4 +17,20 @@ describe 'is_array' do it { is_expected.to run.with_params('one').and_return(false) } it { is_expected.to run.with_params(1).and_return(false) } it { is_expected.to run.with_params({}).and_return(false) } + context 'Checking for deprecation warning' do + after(:context) do + ENV.delete('STDLIB_LOG_DEPRECATIONS') + end + # Checking for deprecation warning, which should only be provoked when the env variable for it is set. + it 'should display a single deprecation' do + ENV['STDLIB_LOG_DEPRECATIONS'] = "true" + scope.expects(:warning).with(includes('This method is deprecated')) + is_expected.to run.with_params(['1.2.3.4']).and_return(true) + end + it 'should display no warning for deprecation' do + ENV['STDLIB_LOG_DEPRECATIONS'] = "false" + scope.expects(:warning).with(includes('This method is deprecated')).never + is_expected.to run.with_params(['1.2.3.4']).and_return(true) + end + end end diff --git a/spec/functions/is_bool_spec.rb b/spec/functions/is_bool_spec.rb index 4550e61..7b2173e 100755 --- a/spec/functions/is_bool_spec.rb +++ b/spec/functions/is_bool_spec.rb @@ -1,12 +1,8 @@ require 'spec_helper' describe 'is_bool' do + it { is_expected.not_to eq(nil) } - # Checking for deprecation warning - it 'should display a single deprecation' do - scope.expects(:warning).with(includes('This method is deprecated')) - is_expected.to run.with_params(true) - end it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } it { is_expected.to run.with_params(true, false).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } it { is_expected.to run.with_params(true).and_return(true) } @@ -17,4 +13,21 @@ describe 'is_bool' do it { is_expected.to run.with_params([true]).and_return(false) } it { is_expected.to run.with_params('true').and_return(false) } it { is_expected.to run.with_params('false').and_return(false) } + context 'Checking for deprecation warning' do + after(:context) do + ENV.delete('STDLIB_LOG_DEPRECATIONS') + end + # Checking for deprecation warning, which should only be provoked when the env variable for it is set. + it 'should display a single deprecation' do + ENV['STDLIB_LOG_DEPRECATIONS'] = "true" + scope.expects(:warning).with(includes('This method is deprecated')) + is_expected.to run.with_params(true).and_return(true) + end + it 'should display no warning for deprecation' do + ENV['STDLIB_LOG_DEPRECATIONS'] = "false" + scope.expects(:warning).with(includes('This method is deprecated')).never + is_expected.to run.with_params(false).and_return(true) + end + end end + diff --git a/spec/functions/is_float_spec.rb b/spec/functions/is_float_spec.rb index cb7e148..44bdc48 100755 --- a/spec/functions/is_float_spec.rb +++ b/spec/functions/is_float_spec.rb @@ -1,13 +1,8 @@ require 'spec_helper' describe 'is_float' do - it { is_expected.not_to eq(nil) } - # Checking for deprecation warning - it 'should display a single deprecation' do - scope.expects(:warning).with(includes('This method is deprecated')) - is_expected.to run.with_params(3) - end + it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } it { is_expected.to run.with_params(0.1, 0.2).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } @@ -26,4 +21,22 @@ describe 'is_float' do it { is_expected.to run.with_params(1.0).and_return(true) } it { is_expected.to run.with_params(1).and_return(false) } end + + context 'Checking for deprecation warning' do + after(:context) do + ENV.delete('STDLIB_LOG_DEPRECATIONS') + end + # Checking for deprecation warning, which should only be provoked when the env variable for it is set. + it 'should display a single deprecation' do + ENV['STDLIB_LOG_DEPRECATIONS'] = "true" + scope.expects(:warning).with(includes('This method is deprecated')) + is_expected.to run.with_params(2.2).and_return(true) + end + it 'should display no warning for deprecation' do + ENV['STDLIB_LOG_DEPRECATIONS'] = "false" + scope.expects(:warning).with(includes('This method is deprecated')).never + is_expected.to run.with_params(1.0).and_return(true) + end + end + end diff --git a/spec/functions/is_integer_spec.rb b/spec/functions/is_integer_spec.rb index 2d68731..4b5dd21 100755 --- a/spec/functions/is_integer_spec.rb +++ b/spec/functions/is_integer_spec.rb @@ -1,14 +1,9 @@ require 'spec_helper' describe 'is_integer' do + it { is_expected.not_to eq(nil) } - # Checking for deprecation warning - it 'should display a single deprecation' do - scope.expects(:warning).with(includes('This method is deprecated')) - is_expected.to run.with_params(3) - end - it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } it { is_expected.to run.with_params(1, 2).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } @@ -16,7 +11,7 @@ describe 'is_integer' do it { is_expected.to run.with_params('3').and_return(true) } it { is_expected.to run.with_params(-3).and_return(true) } it { is_expected.to run.with_params('-3').and_return(true) } - + it { is_expected.to run.with_params(3.7).and_return(false) } it { is_expected.to run.with_params('3.7').and_return(false) } it { is_expected.to run.with_params(-3.7).and_return(false) } @@ -29,4 +24,22 @@ describe 'is_integer' do it { is_expected.to run.with_params(true).and_return(false) } it { is_expected.to run.with_params(false).and_return(false) } it { is_expected.to run.with_params('0001234').and_return(false) } + + context 'Checking for deprecation warning' do + after(:context) do + ENV.delete('STDLIB_LOG_DEPRECATIONS') + end + # Checking for deprecation warning, which should only be provoked when the env variable for it is set. + it 'should display a single deprecation' do + ENV['STDLIB_LOG_DEPRECATIONS'] = "true" + scope.expects(:warning).with(includes('This method is deprecated')) + is_expected.to run.with_params(50).and_return(true) + end + it 'should display no warning for deprecation' do + ENV['STDLIB_LOG_DEPRECATIONS'] = "false" + scope.expects(:warning).with(includes('This method is deprecated')).never + is_expected.to run.with_params(50).and_return(true) + end + end + end diff --git a/spec/functions/is_ip_address_spec.rb b/spec/functions/is_ip_address_spec.rb index 9386ca9..fc8af60 100755 --- a/spec/functions/is_ip_address_spec.rb +++ b/spec/functions/is_ip_address_spec.rb @@ -20,9 +20,21 @@ describe 'is_ip_address' do it { is_expected.to run.with_params(1).and_return(false) } it { is_expected.to run.with_params({}).and_return(false) } it { is_expected.to run.with_params([]).and_return(false) } - # Checking for deprecation warning - it 'should display a single deprecation' do - scope.expects(:warning).with(includes('This method is deprecated')) - is_expected.to run.with_params('1.1.1.1') + + context 'Checking for deprecation warning', if: Puppet.version.to_f < 4.0 do + # Checking for deprecation warning, which should only be provoked when the env variable for it is set. + it 'should display a single deprecation' do + ENV['STDLIB_LOG_DEPRECATIONS'] = "true" + scope.expects(:warning).with(includes('This method is deprecated')) + is_expected.to run.with_params('1.2.3.4').and_return(true) + end + it 'should display no warning for deprecation' do + ENV['STDLIB_LOG_DEPRECATIONS'] = "false" + scope.expects(:warning).with(includes('This method is deprecated')).never + is_expected.to run.with_params('1.2.3.4').and_return(true) + end + after(:context) do + ENV.delete('STDLIB_LOG_DEPRECATIONS') + end end end diff --git a/spec/functions/is_ipv4_address_spec.rb b/spec/functions/is_ipv4_address_spec.rb index 2b9fc49..9d53a9d 100644 --- a/spec/functions/is_ipv4_address_spec.rb +++ b/spec/functions/is_ipv4_address_spec.rb @@ -1,6 +1,7 @@ require 'spec_helper' describe 'is_ipv4_address' do + it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } it { is_expected.to run.with_params('1.2.3.4').and_return(true) } @@ -9,9 +10,21 @@ describe 'is_ipv4_address' do it { is_expected.to run.with_params('1.2.3.4.5').and_return(false) } it { is_expected.to run.with_params('').and_return(false) } it { is_expected.to run.with_params('one').and_return(false) } - # Checking for deprecation warning - it 'should display a single deprecation' do - scope.expects(:warning).with(includes('This method is deprecated')) - is_expected.to run.with_params('1.1.1.1') + + context 'Checking for deprecation warning', if: Puppet.version.to_f < 4.0 do + after(:context) do + ENV.delete('STDLIB_LOG_DEPRECATIONS') + end + # Checking for deprecation warning, which should only be provoked when the env variable for it is set. + it 'should display a single deprecation' do + ENV['STDLIB_LOG_DEPRECATIONS'] = "true" + scope.expects(:warning).with(includes('This method is deprecated')) + is_expected.to run.with_params('1.2.3.4').and_return(true) + end + it 'should display no warning for deprecation' do + ENV['STDLIB_LOG_DEPRECATIONS'] = "false" + scope.expects(:warning).with(includes('This method is deprecated')).never + is_expected.to run.with_params('1.2.3.4').and_return(true) + end end end diff --git a/spec/functions/is_ipv6_address_spec.rb b/spec/functions/is_ipv6_address_spec.rb index e3e4734..4449fea 100644 --- a/spec/functions/is_ipv6_address_spec.rb +++ b/spec/functions/is_ipv6_address_spec.rb @@ -1,6 +1,7 @@ require 'spec_helper' describe 'is_ipv6_address' do + it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } it { is_expected.to run.with_params('2001:0db8:85a3:0000:0000:8a2e:0370:7334').and_return(true) } @@ -9,9 +10,21 @@ describe 'is_ipv6_address' do it { is_expected.to run.with_params('1.2.3.4.5').and_return(false) } it { is_expected.to run.with_params('').and_return(false) } it { is_expected.to run.with_params('one').and_return(false) } - # Checking for deprecation warning - it 'should display a single deprecation' do - scope.expects(:warning).with(includes('This method is deprecated')) - is_expected.to run.with_params('2001:0db8:85a3:0000:0000:8a2e:0370:7334') + + context 'Checking for deprecation warning', if: Puppet.version.to_f < 4.0 do + after(:context) do + ENV.delete('STDLIB_LOG_DEPRECATIONS') + end + # Checking for deprecation warning, which should only be provoked when the env variable for it is set. + it 'should display a single deprecation' do + ENV['STDLIB_LOG_DEPRECATIONS'] = "true" + scope.expects(:warning).with(includes('This method is deprecated')) + is_expected.to run.with_params('2001:0db8:85a3:0000:0000:8a2e:0370:7334').and_return(true) + end + it 'should display no warning for deprecation' do + ENV['STDLIB_LOG_DEPRECATIONS'] = "false" + scope.expects(:warning).with(includes('This method is deprecated')).never + is_expected.to run.with_params('2001:0db8:85a3:0000:0000:8a2e:0370:7334').and_return(true) + end end end diff --git a/spec/functions/is_numeric_spec.rb b/spec/functions/is_numeric_spec.rb index f4ead56..ccfb9d8 100755 --- a/spec/functions/is_numeric_spec.rb +++ b/spec/functions/is_numeric_spec.rb @@ -1,14 +1,9 @@ require 'spec_helper' describe 'is_numeric' do + it { is_expected.not_to eq(nil) } - # Checking for deprecation warning - it 'should display a single deprecation' do - scope.expects(:warning).with(includes('This method is deprecated')) - is_expected.to run.with_params(3) - end - it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } it { is_expected.to run.with_params(1, 2).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } @@ -32,4 +27,22 @@ describe 'is_numeric' do it { is_expected.to run.with_params(false).and_return(false) } it { is_expected.to run.with_params('0001234').and_return(false) } it { is_expected.to run.with_params(' - 1234').and_return(false) } + + context 'Checking for deprecation warning' do + after(:context) do + ENV.delete('STDLIB_LOG_DEPRECATIONS') + end + # Checking for deprecation warning, which should only be provoked when the env variable for it is set. + it 'should display a single deprecation' do + ENV['STDLIB_LOG_DEPRECATIONS'] = "true" + scope.expects(:warning).with(includes('This method is deprecated')) + is_expected.to run.with_params(7).and_return(true) + end + it 'should display no warning for deprecation' do + ENV['STDLIB_LOG_DEPRECATIONS'] = "false" + scope.expects(:warning).with(includes('This method is deprecated')).never + is_expected.to run.with_params(7).and_return(true) + end + end + end diff --git a/spec/functions/is_string_spec.rb b/spec/functions/is_string_spec.rb index 4f59b63..460d6e0 100755 --- a/spec/functions/is_string_spec.rb +++ b/spec/functions/is_string_spec.rb @@ -1,12 +1,8 @@ require 'spec_helper' describe 'is_string' do + it { is_expected.not_to eq(nil) } - # Checking for deprecation warning - it 'should display a single deprecation' do - scope.expects(:warning).with(includes('This method is deprecated')) - is_expected.to run.with_params('ha') - end it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } it { pending("Current implementation ignores parameters after the first.") @@ -30,4 +26,22 @@ describe 'is_string' do it { is_expected.to run.with_params(false).and_return(false) } it { is_expected.to run.with_params('one').and_return(true) } it { is_expected.to run.with_params('0001234').and_return(true) } + + context 'Checking for deprecation warning' do + after(:context) do + ENV.delete('STDLIB_LOG_DEPRECATIONS') + end + # Checking for deprecation warning, which should only be provoked when the env variable for it is set. + it 'should display a single deprecation' do + ENV['STDLIB_LOG_DEPRECATIONS'] = "true" + scope.expects(:warning).with(includes('This method is deprecated')) + is_expected.to run.with_params('sponge').and_return(true) + end + it 'should display no warning for deprecation' do + ENV['STDLIB_LOG_DEPRECATIONS'] = "false" + scope.expects(:warning).with(includes('This method is deprecated')).never + is_expected.to run.with_params('bob').and_return(true) + end + end + end diff --git a/spec/functions/validate_absolute_path_spec.rb b/spec/functions/validate_absolute_path_spec.rb index dbac88f..75df6bc 100755 --- a/spec/functions/validate_absolute_path_spec.rb +++ b/spec/functions/validate_absolute_path_spec.rb @@ -1,9 +1,14 @@ require 'spec_helper' describe 'validate_absolute_path' do + after(:context) do + ENV.delete('STDLIB_LOG_DEPRECATIONS') + end + # Checking for deprecation warning it 'should display a single deprecation' do # called twice because validate_absolute_path calls is_absolute_path + ENV['STDLIB_LOG_DEPRECATIONS'] = "true" scope.expects(:warning).with(includes('This method is deprecated')).twice is_expected.to run.with_params('c:/') end diff --git a/spec/functions/validate_array_spec.rb b/spec/functions/validate_array_spec.rb index 9f2e210..f395d16 100755 --- a/spec/functions/validate_array_spec.rb +++ b/spec/functions/validate_array_spec.rb @@ -1,10 +1,15 @@ require 'spec_helper' describe 'validate_array' do + describe 'signature validation' do + after(:context) do + ENV.delete('STDLIB_LOG_DEPRECATIONS') + end it { is_expected.not_to eq(nil) } # Checking for deprecation warning it 'should display a single deprecation' do + ENV['STDLIB_LOG_DEPRECATIONS'] = "true" scope.expects(:warning).with(includes('This method is deprecated')) is_expected.to run.with_params([]) end diff --git a/spec/functions/validate_bool_spec.rb b/spec/functions/validate_bool_spec.rb index 724e31f..4bd1453 100755 --- a/spec/functions/validate_bool_spec.rb +++ b/spec/functions/validate_bool_spec.rb @@ -1,9 +1,14 @@ require 'spec_helper' describe 'validate_bool' do + after(:context) do + ENV.delete('STDLIB_LOG_DEPRECATIONS') + end + # Checking for deprecation warning it 'should display a single deprecation' do #called twice, because validate_bool calls is_bool + ENV['STDLIB_LOG_DEPRECATIONS'] = "true" scope.expects(:warning).with(includes('This method is deprecated')).twice is_expected.to run.with_params(true) end diff --git a/spec/functions/validate_integer_spec.rb b/spec/functions/validate_integer_spec.rb index 3ca50b2..ffc59f8 100755 --- a/spec/functions/validate_integer_spec.rb +++ b/spec/functions/validate_integer_spec.rb @@ -1,8 +1,13 @@ require 'spec_helper' describe 'validate_integer' do + after(:context) do + ENV.delete('STDLIB_LOG_DEPRECATIONS') + end + # Checking for deprecation warning it 'should display a single deprecation' do + ENV['STDLIB_LOG_DEPRECATIONS'] = "true" scope.expects(:warning).with(includes('This method is deprecated')) is_expected.to run.with_params(3) end diff --git a/spec/functions/validate_ip_address_spec.rb b/spec/functions/validate_ip_address_spec.rb index 10f6c37..7040a8d 100644 --- a/spec/functions/validate_ip_address_spec.rb +++ b/spec/functions/validate_ip_address_spec.rb @@ -1,6 +1,7 @@ require 'spec_helper' describe 'validate_ip_address' do + describe 'signature validation' do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } @@ -19,10 +20,24 @@ describe 'validate_ip_address' do it { is_expected.to run.with_params('3ffe:0505:0002::', '3ffe:0505:0002::2') } it { is_expected.to run.with_params('::1/64') } it { is_expected.to run.with_params('fe80::a00:27ff:fe94:44d6/64') } - it 'should display a single deprecation' do - scope.expects(:warning).with(includes('This method is deprecated')) - is_expected.to run.with_params('1.1.1.1') + + context 'Checking for deprecation warning', if: Puppet.version.to_f < 4.0 do + after(:context) do + ENV.delete('STDLIB_LOG_DEPRECATIONS') + end + # Checking for deprecation warning, which should only be provoked when the env variable for it is set. + it 'should display a single deprecation' do + ENV['STDLIB_LOG_DEPRECATIONS'] = "true" + scope.expects(:warning).with(includes('This method is deprecated')) + is_expected.to run.with_params('1.2.3.4') + end + it 'should display no warning for deprecation' do + ENV['STDLIB_LOG_DEPRECATIONS'] = "false" + scope.expects(:warning).with(includes('This method is deprecated')).never + is_expected.to run.with_params('1.2.3.4') + end end + context 'with netmasks' do it { is_expected.to run.with_params('8.8.8.8/0') } it { is_expected.to run.with_params('8.8.8.8/16') } diff --git a/spec/functions/validate_ipv4_address_spec.rb b/spec/functions/validate_ipv4_address_spec.rb index b67bf6f..b60dc8e 100755 --- a/spec/functions/validate_ipv4_address_spec.rb +++ b/spec/functions/validate_ipv4_address_spec.rb @@ -1,45 +1,58 @@ require 'spec_helper' describe 'validate_ipv4_address' do + describe 'signature validation' do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + end + context 'Checking for deprecation warning', if: Puppet.version.to_f < 4.0 do + after(:context) do + ENV.delete('STDLIB_LOG_DEPRECATIONS') + end + # Checking for deprecation warning, which should only be provoked when the env variable for it is set. it 'should display a single deprecation' do + ENV['STDLIB_LOG_DEPRECATIONS'] = "true" scope.expects(:warning).with(includes('This method is deprecated')) - is_expected.to run.with_params('1.1.1.1') + is_expected.to run.with_params('1.2.3.4') end - - describe 'valid inputs' do - it { is_expected.to run.with_params('0.0.0.0') } - it { is_expected.to run.with_params('8.8.8.8') } - it { is_expected.to run.with_params('127.0.0.1') } - it { is_expected.to run.with_params('10.10.10.10') } - it { is_expected.to run.with_params('194.232.104.150') } - it { is_expected.to run.with_params('244.24.24.24') } - it { is_expected.to run.with_params('255.255.255.255') } - it { is_expected.to run.with_params('1.2.3.4', '5.6.7.8') } - context 'with netmasks' do - it { is_expected.to run.with_params('8.8.8.8/0') } - it { is_expected.to run.with_params('8.8.8.8/16') } - it { is_expected.to run.with_params('8.8.8.8/32') } - it { is_expected.to run.with_params('8.8.8.8/255.255.0.0') } - end + it 'should display no warning for deprecation' do + ENV['STDLIB_LOG_DEPRECATIONS'] = "false" + scope.expects(:warning).with(includes('This method is deprecated')).never + is_expected.to run.with_params('1.2.3.4') end + end - describe 'invalid inputs' do - it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, /is not a string/) } - it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /is not a string/) } - it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, /is not a string/) } - it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, /is not a valid IPv4/) } - it { is_expected.to run.with_params('0.0.0').and_raise_error(Puppet::ParseError, /is not a valid IPv4/) } - it { is_expected.to run.with_params('0.0.0.256').and_raise_error(Puppet::ParseError, /is not a valid IPv4/) } - it { is_expected.to run.with_params('0.0.0.0.0').and_raise_error(Puppet::ParseError, /is not a valid IPv4/) } - it { is_expected.to run.with_params('affe::beef').and_raise_error(Puppet::ParseError, /is not a valid IPv4/) } - it { is_expected.to run.with_params('1.2.3.4', {}).and_raise_error(Puppet::ParseError, /is not a string/) } - it { is_expected.to run.with_params('1.2.3.4', 1).and_raise_error(Puppet::ParseError, /is not a string/) } - it { is_expected.to run.with_params('1.2.3.4', true).and_raise_error(Puppet::ParseError, /is not a string/) } - it { is_expected.to run.with_params('1.2.3.4', 'one').and_raise_error(Puppet::ParseError, /is not a valid IPv4/) } + describe 'valid inputs' do + it { is_expected.to run.with_params('0.0.0.0') } + it { is_expected.to run.with_params('8.8.8.8') } + it { is_expected.to run.with_params('127.0.0.1') } + it { is_expected.to run.with_params('10.10.10.10') } + it { is_expected.to run.with_params('194.232.104.150') } + it { is_expected.to run.with_params('244.24.24.24') } + it { is_expected.to run.with_params('255.255.255.255') } + it { is_expected.to run.with_params('1.2.3.4', '5.6.7.8') } + context 'with netmasks' do + it { is_expected.to run.with_params('8.8.8.8/0') } + it { is_expected.to run.with_params('8.8.8.8/16') } + it { is_expected.to run.with_params('8.8.8.8/32') } + it { is_expected.to run.with_params('8.8.8.8/255.255.0.0') } end end + + describe 'invalid inputs' do + it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, /is not a string/) } + it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /is not a string/) } + it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, /is not a string/) } + it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, /is not a valid IPv4/) } + it { is_expected.to run.with_params('0.0.0').and_raise_error(Puppet::ParseError, /is not a valid IPv4/) } + it { is_expected.to run.with_params('0.0.0.256').and_raise_error(Puppet::ParseError, /is not a valid IPv4/) } + it { is_expected.to run.with_params('0.0.0.0.0').and_raise_error(Puppet::ParseError, /is not a valid IPv4/) } + it { is_expected.to run.with_params('affe::beef').and_raise_error(Puppet::ParseError, /is not a valid IPv4/) } + it { is_expected.to run.with_params('1.2.3.4', {}).and_raise_error(Puppet::ParseError, /is not a string/) } + it { is_expected.to run.with_params('1.2.3.4', 1).and_raise_error(Puppet::ParseError, /is not a string/) } + it { is_expected.to run.with_params('1.2.3.4', true).and_raise_error(Puppet::ParseError, /is not a string/) } + it { is_expected.to run.with_params('1.2.3.4', 'one').and_raise_error(Puppet::ParseError, /is not a valid IPv4/) } + end end diff --git a/spec/functions/validate_ipv6_address_spec.rb b/spec/functions/validate_ipv6_address_spec.rb index 3afab56..87b535e 100755 --- a/spec/functions/validate_ipv6_address_spec.rb +++ b/spec/functions/validate_ipv6_address_spec.rb @@ -1,36 +1,50 @@ require 'spec_helper' describe 'validate_ipv6_address' do + describe 'signature validation' do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) } + end - describe 'valid inputs' do - it { is_expected.to run.with_params('3ffe:0505:0002::') } - it { is_expected.to run.with_params('3ffe:0505:0002::', '3ffe:0505:0002::2') } - it { is_expected.to run.with_params('::1/64') } - it { is_expected.to run.with_params('fe80::a00:27ff:fe94:44d6/64') } - it 'should display a single deprecation' do - scope.expects(:warning).with(includes('This method is deprecated')) - is_expected.to run.with_params('3ffe:0505:0002::') - end + context 'Checking for deprecation warning', if: Puppet.version.to_f < 4.0 do + after(:context) do + ENV.delete('STDLIB_LOG_DEPRECATIONS') + end + # Checking for deprecation warning, which should only be provoked when the env variable for it is set. + it 'should display a single deprecation' do + ENV['STDLIB_LOG_DEPRECATIONS'] = "true" + scope.expects(:warning).with(includes('This method is deprecated')) + is_expected.to run.with_params('3ffe:0505:0002::') + end + it 'should display no warning for deprecation' do + ENV['STDLIB_LOG_DEPRECATIONS'] = "false" + scope.expects(:warning).with(includes('This method is deprecated')).never + is_expected.to run.with_params('3ffe:0505:0002::') end + end + + describe 'valid inputs' do + it { is_expected.to run.with_params('3ffe:0505:0002::') } + it { is_expected.to run.with_params('3ffe:0505:0002::', '3ffe:0505:0002::2') } + it { is_expected.to run.with_params('::1/64') } + it { is_expected.to run.with_params('fe80::a00:27ff:fe94:44d6/64') } + end - describe 'invalid inputs' do - it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, /is not a string/) } - it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, /is not a string/) } - it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } - it { is_expected.to run.with_params('0.0.0').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } - it { is_expected.to run.with_params('0.0.0.256').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } - it { is_expected.to run.with_params('0.0.0.0.0').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } - it { is_expected.to run.with_params('affe:beef').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } - it { is_expected.to run.with_params('::1', {}).and_raise_error(Puppet::ParseError, /is not a string/) } - it { is_expected.to run.with_params('::1', true).and_raise_error(Puppet::ParseError, /is not a string/) } - it { is_expected.to run.with_params('::1', 'one').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } - context 'unless running on ruby 1.8.7', :if => RUBY_VERSION != '1.8.7' do - it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /is not a string/) } - it { is_expected.to run.with_params('::1', 1).and_raise_error(Puppet::ParseError, /is not a string/) } - end + describe 'invalid inputs' do + it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, /is not a string/) } + it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, /is not a string/) } + it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } + it { is_expected.to run.with_params('0.0.0').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } + it { is_expected.to run.with_params('0.0.0.256').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } + it { is_expected.to run.with_params('0.0.0.0.0').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } + it { is_expected.to run.with_params('affe:beef').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } + it { is_expected.to run.with_params('::1', {}).and_raise_error(Puppet::ParseError, /is not a string/) } + it { is_expected.to run.with_params('::1', true).and_raise_error(Puppet::ParseError, /is not a string/) } + it { is_expected.to run.with_params('::1', 'one').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) } + context 'unless running on ruby 1.8.7', :if => RUBY_VERSION != '1.8.7' do + it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /is not a string/) } + it { is_expected.to run.with_params('::1', 1).and_raise_error(Puppet::ParseError, /is not a string/) } end end end diff --git a/spec/functions/validate_numeric_spec.rb b/spec/functions/validate_numeric_spec.rb index 2869e5f..4a65649 100755 --- a/spec/functions/validate_numeric_spec.rb +++ b/spec/functions/validate_numeric_spec.rb @@ -1,8 +1,13 @@ require 'spec_helper' describe 'validate_numeric' do + after(:context) do + ENV.delete('STDLIB_LOG_DEPRECATIONS') + end + # Checking for deprecation warning it 'should display a single deprecation' do + ENV['STDLIB_LOG_DEPRECATIONS'] = "true" scope.expects(:warning).with(includes('This method is deprecated')) is_expected.to run.with_params(3) end diff --git a/spec/functions/validate_re_spec.rb b/spec/functions/validate_re_spec.rb index 4b78a2e..2ee3f47 100755 --- a/spec/functions/validate_re_spec.rb +++ b/spec/functions/validate_re_spec.rb @@ -1,8 +1,13 @@ require 'spec_helper' describe 'validate_re' do + after(:context) do + ENV.delete('STDLIB_LOG_DEPRECATIONS') + end + # Checking for deprecation warning it 'should display a single deprecation' do + ENV['STDLIB_LOG_DEPRECATIONS'] = "true" scope.expects(:warning).with(includes('This method is deprecated')) is_expected.to run.with_params('', '') end diff --git a/spec/functions/validate_string_spec.rb b/spec/functions/validate_string_spec.rb index ef7a1b4..45d6ffc 100755 --- a/spec/functions/validate_string_spec.rb +++ b/spec/functions/validate_string_spec.rb @@ -1,8 +1,13 @@ require 'spec_helper' describe 'validate_string' do + after(:context) do + ENV.delete('STDLIB_LOG_DEPRECATIONS') + end + # Checking for deprecation warning it 'should display a single deprecation' do + ENV['STDLIB_LOG_DEPRECATIONS'] = "true" scope.expects(:warning).with(includes('This method is deprecated')) is_expected.to run.with_params('', '') end |