summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Gemfile2
-rw-r--r--README.markdown5
-rw-r--r--lib/puppet/functions/deprecation.rb8
-rw-r--r--lib/puppet/functions/validate_legacy.rb31
-rw-r--r--lib/puppet/parser/functions/deprecation.rb8
-rw-r--r--lib/puppet/parser/functions/dig44.rb37
-rw-r--r--spec/classes/validate_legacy_spec.rb39
-rw-r--r--spec/fixtures/test/manifests/validate_legacy.pp18
-rwxr-xr-xspec/functions/assert_private_spec.rb30
-rw-r--r--spec/functions/deprecation_spec.rb4
-rw-r--r--spec/functions/dig44_spec.rb119
-rwxr-xr-xspec/functions/is_array_spec.rb22
-rwxr-xr-xspec/functions/is_bool_spec.rb23
-rwxr-xr-xspec/functions/is_float_spec.rb25
-rwxr-xr-xspec/functions/is_integer_spec.rb27
-rwxr-xr-xspec/functions/is_ip_address_spec.rb20
-rw-r--r--spec/functions/is_ipv4_address_spec.rb21
-rw-r--r--spec/functions/is_ipv6_address_spec.rb21
-rwxr-xr-xspec/functions/is_numeric_spec.rb25
-rwxr-xr-xspec/functions/is_string_spec.rb24
-rwxr-xr-xspec/functions/validate_absolute_path_spec.rb5
-rwxr-xr-xspec/functions/validate_array_spec.rb5
-rwxr-xr-xspec/functions/validate_bool_spec.rb5
-rwxr-xr-xspec/functions/validate_integer_spec.rb5
-rw-r--r--spec/functions/validate_ip_address_spec.rb21
-rwxr-xr-xspec/functions/validate_ipv4_address_spec.rb73
-rwxr-xr-xspec/functions/validate_ipv6_address_spec.rb62
-rw-r--r--spec/functions/validate_legacy_spec.rb68
-rwxr-xr-xspec/functions/validate_numeric_spec.rb5
-rwxr-xr-xspec/functions/validate_re_spec.rb21
-rwxr-xr-xspec/functions/validate_string_spec.rb5
31 files changed, 529 insertions, 255 deletions
diff --git a/Gemfile b/Gemfile
index c97275b..ecf3d06 100644
--- a/Gemfile
+++ b/Gemfile
@@ -21,7 +21,7 @@ group :development, :unit_tests do
gem 'puppet_facts'
gem 'puppet-blacksmith', '>= 3.4.0'
gem 'puppetlabs_spec_helper', '>= 1.2.1'
- gem 'rspec-puppet', '>= 2.3.2'
+ gem 'rspec-puppet', '>= 2.3.2', :git => 'https://github.com/rodjek/rspec-puppet.git', :branch => 'fb27c533e2664057fba4b73d0bd902a946abfce0'
gem 'rspec-puppet-facts'
gem 'simplecov'
gem 'parallel_tests'
diff --git a/README.markdown b/README.markdown
index 13a5b74..667da33 100644
--- a/README.markdown
+++ b/README.markdown
@@ -304,7 +304,7 @@ Deletes all instances of the undef value from an array or hash. For example, `$h
#### `deprecation`
-Function to print deprecation warnings, Logs a warning once for a given key. The uniqueness key - can appear once. The msg is the message text including any positional information that is formatted by the user/caller of the method It is affected by the puppet setting 'strict', which can be set to :error (outputs as an error message), :off (no message / error is displayed) and :warning (default, outputs a warning) *Type*: String, String.
+A function to print deprecation warnings, logs a warning once for a given key. The uniqueness key - can appear once. The msg is the message text including any positional information that is formatted by the user/caller of the method. It is affected by the puppet setting 'strict', which can be set to :error (outputs as an error message), :off (no message / error is displayed) and :warning (default, outputs a warning). In Puppet version less than 4.0 an environment variable can be set to decide whether or not to log deprecation warnings (ENV[STDLIB_LOG_DEPRECATION]). If this environment variable is set to true, the functions will log a warning. *Type*: String, String.
#### `difference`
@@ -1395,6 +1395,7 @@ Many `validate_*` functions have surprising holes in their validation. For examp
To start out, for each parameter of your classes and defines, you'll have to decide on a new Puppet 4 data type to use. In most cases the new data type will allow a different set of values than the original `validate_*` function (which is the point of the whole exercise). The situation then looks like this:
| | `validate_` pass | `validate_` fail |
+| ------------ | ---------------- | ---------------- |
| matches type | pass | pass, notice |
| fails type | pass, deprecated | fail |
@@ -1436,7 +1437,7 @@ Example:
#### `validate_numeric`
-Validates that the first argument is a numeric value (or an array of numeric values). Aborts catalog compilation if any of the checks fail.
+Validates that the first argument is a numeric value (or an array or string of numeric values). Aborts catalog compilation if any of the checks fail.
The second argument is optional and passes a maximum. (All elements of) the first argument has to be less or equal to this max.
diff --git a/lib/puppet/functions/deprecation.rb b/lib/puppet/functions/deprecation.rb
index 3b84ae5..30aeb1d 100644
--- a/lib/puppet/functions/deprecation.rb
+++ b/lib/puppet/functions/deprecation.rb
@@ -1,5 +1,4 @@
# Function to print deprecation warnings, Logs a warning once for a given key. The uniqueness key - can appear once. The msg is the message text including any positional information that is formatted by the user/caller of the method It is affected by the puppet setting 'strict', which can be set to :error (outputs as an error message), :off (no message / error is displayed) and :warning (default, outputs a warning) *Type*: String, String.
-#
Puppet::Functions.create_function(:deprecation) do
dispatch :deprecation do
@@ -9,13 +8,16 @@ Puppet::Functions.create_function(:deprecation) do
def deprecation(key, message)
# depending on configuration setting of strict
+ caller_infos = caller.first.split(":")
case Puppet.settings[:strict]
when :off
# do nothing
when :error
- fail("deprecation. #{key}. #{message}")
+ err_message = "#{message} : #{caller_infos[0]} : #{caller_infos[1]}"
+ fail("deprecation. #{key}. #{err_message}")
else
- Puppet.warn_once('deprecation', key, message)
+ err_message = "#{message} : #{caller_infos[0]} : #{caller_infos[1]}"
+ Puppet.deprecation_warning(err_message, key)
end
end
end
diff --git a/lib/puppet/functions/validate_legacy.rb b/lib/puppet/functions/validate_legacy.rb
index 9d7d012..0ba6dd8 100644
--- a/lib/puppet/functions/validate_legacy.rb
+++ b/lib/puppet/functions/validate_legacy.rb
@@ -2,46 +2,49 @@ Puppet::Functions.create_function(:validate_legacy, Puppet::Functions::InternalF
# The function checks a value against both the target_type (new) and the previous_validation function (old).
dispatch :validate_legacy do
+ scope_param
param 'Type', :target_type
- param 'String', :previous_validation
- param 'NotUndef', :value
- optional_param 'Any', :args
+ param 'String', :function_name
+ param 'Any', :value
+ optional_repeated_param 'Any', :args
end
+
dispatch :validate_legacy_s do
scope_param
param 'String', :type_string
- param 'String', :previous_validation
- param 'NotUndef', :value
+ param 'String', :function_name
+ param 'Any', :value
optional_repeated_param 'Any', :args
end
def validate_legacy_s(scope, type_string, *args)
t = Puppet::Pops::Types::TypeParser.new.parse(type_string, scope)
- validate_legacy(t, *args)
+ validate_legacy(scope, t, *args)
end
- def validate_legacy(target_type, previous_validation, value, *prev_args)
+ def validate_legacy(scope, target_type, function_name, value, *prev_args)
if assert_type(target_type, value)
- if previous_validation(previous_validation, value, *prev_args)
+ if previous_validation(scope, function_name, value, *prev_args)
# Silently passes
else
- Puppet.warn("Accepting previously invalid value for target_type '#{target_type}'")
+ Puppet.notice("Accepting previously invalid value for target type '#{target_type}'")
end
else
+ caller_infos = caller.first.split(":")
inferred_type = Puppet::Pops::Types::TypeCalculator.infer_set(value)
- error_msg = Puppet::Pops::Types::TypeMismatchDescriber.new.describe_mismatch(previous_validation, target_type, inferred_type)
- if previous_validation(previous_validation, value, *prev_args)
- Puppet.warn(error_msg)
+ error_msg = Puppet::Pops::Types::TypeMismatchDescriber.new.describe_mismatch("validate_legacy(#{function_name}) [#{caller_infos[0]}:#{caller_infos[1]}]", target_type, inferred_type)
+ if previous_validation(scope, function_name, value, *prev_args)
+ call_function('deprecation', 'validate_legacy', error_msg)
else
call_function('fail', error_msg)
end
end
end
- def previous_validation(previous_validation, value, *prev_args)
+ def previous_validation(scope, function_name, value, *prev_args)
# Call the previous validation function and catch any errors. Return true if no errors are thrown.
begin
- call_function(previous_validation, value, *prev_args)
+ scope.send("function_#{function_name}".to_s, [value, *prev_args])
true
rescue Puppet::ParseError
false
diff --git a/lib/puppet/parser/functions/deprecation.rb b/lib/puppet/parser/functions/deprecation.rb
index fc861a6..0cb247d 100644
--- a/lib/puppet/parser/functions/deprecation.rb
+++ b/lib/puppet/parser/functions/deprecation.rb
@@ -9,7 +9,11 @@ EOS
key = arguments[0]
message = arguments[1]
-
- warning("deprecation. #{key}. #{message}")
+
+ if ENV['STDLIB_LOG_DEPRECATIONS'] == "true"
+ caller_infos = caller.first.split(":")
+ err_message = "#{message} : #{caller_infos[0]} : #{caller_infos[1]}"
+ warning("deprecation. #{key}. #{err_message}")
+ end
end
end
diff --git a/lib/puppet/parser/functions/dig44.rb b/lib/puppet/parser/functions/dig44.rb
index a7de363..1e7c318 100644
--- a/lib/puppet/parser/functions/dig44.rb
+++ b/lib/puppet/parser/functions/dig44.rb
@@ -3,21 +3,28 @@
#
module Puppet::Parser::Functions
- newfunction(:dig44, :type => :rvalue, :doc => <<-EOS
+ newfunction(
+ :dig44,
+ :type => :rvalue,
+ :arity => -2,
+ :doc => <<-eos
DEPRECATED: This function has been replaced in puppet 4.5.0.
-Looks up into a complex structure of arrays and hashes and returns nil
+Looks up into a complex structure of arrays and hashes and returns a value
or the default value if nothing was found.
-Path is an array of keys to be looked up in data argument. The function
-will go down the structure and try to extract the required value.
+Key can contain slashes to describe path components. The function will go down
+the structure and try to extract the required value.
$data = {
'a' => {
'b' => [
'b1',
'b2',
- 'b3' ]}}
+ 'b3',
+ ]
+ }
+}
$value = dig44($data, ['a', 'b', '2'], 'not_found')
=> $value = 'b3'
@@ -29,18 +36,18 @@ b -> second hash key
not_found -> (optional) will be returned if there is no value or the path
did not match. Defaults to nil.
-In addition to the required "path" argument, "dig44" accepts default
+In addition to the required "key" argument, the function accepts a default
argument. It will be returned if no value was found or a path component is
missing. And the fourth argument can set a variable path separator.
- EOS
- ) do |arguments|
+ eos
+ ) do |arguments|
# Two arguments are required
raise(Puppet::ParseError, "dig44(): Wrong number of arguments " +
"given (#{arguments.size} for at least 2)") if arguments.size < 2
data, path, default = *arguments
- if !(data.is_a?(Hash) || data.is_a?(Array))
+ unless data.is_a?(Hash) or data.is_a?(Array)
raise(Puppet::ParseError, "dig44(): first argument must be a hash or an array, " <<
"given #{data.class.name}")
end
@@ -50,7 +57,17 @@ missing. And the fourth argument can set a variable path separator.
"given #{path.class.name}")
end
- value = path.reduce(data) { |h, k| (h.is_a?(Hash) || h.is_a?(Array)) ? h[k] : break }
+ value = path.reduce(data) do |structure, key|
+ if structure.is_a? Hash or structure.is_a? Array
+ if structure.is_a? Array
+ key = Integer key rescue break
+ end
+ break if structure[key].nil? or structure[key] == :undef
+ structure[key]
+ else
+ break
+ end
+ end
value.nil? ? default : value
end
end
diff --git a/spec/classes/validate_legacy_spec.rb b/spec/classes/validate_legacy_spec.rb
deleted file mode 100644
index ded6890..0000000
--- a/spec/classes/validate_legacy_spec.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-require 'spec_helper'
-
-if Puppet.version.to_f >= 4.0
- # validate_legacy requires a proper scope to run, so we have to trigger a true compilation here,
- # instead of being able to leverage the function test group.
- describe 'test::validate_legacy', type: :class do
-
- describe 'validate_legacy passes assertion of type but not previous validation' do
- let(:params) {{ type: "Optional[Integer]", prev_validation: "validate_re", value: 5, previous_arg1: ["^\\d+$", ""] }}
- it {
- Puppet.expects(:warn).with(includes('Accepting previously invalid value for target_type'))
- is_expected.to compile
- }
- end
-
- describe 'validate_legacy passes assertion of type and previous validation' do
- let(:params) {{ type: "Optional[String]", prev_validation: "validate_re", value: "5", previous_arg1: ["."] }}
- it { is_expected.to compile }
- end
-
- describe 'validate_legacy fails assertion of type and passes previous validation' do
- let(:params) {{ type: "Optional[Integer]", prev_validation: "validate_re", value: "5", previous_arg1: ["."] }}
- it {
- Puppet.expects(:warn).with(includes('expected'))
- is_expected.to compile
- }
- end
-
- describe 'validate_legacy fails assertion and fails previous validation' do
- let(:params) {{ type: "Optional[Integer]", prev_validation: "validate_re", value: "5", previous_arg1: ["thisisnotright"] }}
- it { is_expected.to compile.and_raise_error(/Error while evaluating a Function Call, \w* expected an \w* value, got \w*/) }
- end
-
- describe 'validate_legacy works with multi-argument validate_ functions' do
- let(:params) {{ type: "Integer", prev_validation: "validate_integer", value: 10, previous_arg1: 100, previous_arg2: 0 }}
- it { is_expected.to compile }
- end
- end
-end
diff --git a/spec/fixtures/test/manifests/validate_legacy.pp b/spec/fixtures/test/manifests/validate_legacy.pp
deleted file mode 100644
index 706df88..0000000
--- a/spec/fixtures/test/manifests/validate_legacy.pp
+++ /dev/null
@@ -1,18 +0,0 @@
-# Class to test stdlib validate_legacy function
-
-class test::validate_legacy(
- $type,
- $prev_validation,
- $value,
- $previous_arg1,
- $previous_arg2 = undef,
- ) {
-
- if $previous_arg2 == undef {
- validate_legacy( $type, $prev_validation, $value, $previous_arg1 )
- } else {
- validate_legacy( $type, $prev_validation, $value, $previous_arg1, $previous_arg2 )
- }
- notice("Success")
-
-}
diff --git a/spec/functions/assert_private_spec.rb b/spec/functions/assert_private_spec.rb
index 98f2598..355e0dd 100755
--- a/spec/functions/assert_private_spec.rb
+++ b/spec/functions/assert_private_spec.rb
@@ -5,31 +5,26 @@ describe 'assert_private' do
it "should not fail" do
scope.expects(:lookupvar).with('module_name').returns('foo')
scope.expects(:lookupvar).with('caller_module_name').returns('foo')
- expect {
- subject.call []
- }.not_to raise_error
+
+ is_expected.to run.with_params()
end
end
- context "with an explicit failure message" do
- it "prints the failure message on error" do
+ context "when called from private class" do
+ before :each do
scope.expects(:lookupvar).with('module_name').returns('foo')
scope.expects(:lookupvar).with('caller_module_name').returns('bar')
- expect {
- subject.call ['failure message!']
- }.to raise_error Puppet::ParseError, /failure message!/
end
- end
- context "when called from private class" do
it "should fail with a class error message" do
- scope.expects(:lookupvar).with('module_name').returns('foo')
- scope.expects(:lookupvar).with('caller_module_name').returns('bar')
scope.source.expects(:name).returns('foo::baz')
scope.source.expects(:type).returns('hostclass')
- expect {
- subject.call []
- }.to raise_error Puppet::ParseError, /Class foo::baz is private/
+
+ is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /Class foo::baz is private/)
+ end
+
+ context "with an explicit failure message" do
+ it { is_expected.to run.with_params('failure message!').and_raise_error(Puppet::ParseError, /failure message!/) }
end
end
@@ -39,9 +34,8 @@ describe 'assert_private' do
scope.expects(:lookupvar).with('caller_module_name').returns('bar')
scope.source.expects(:name).returns('foo::baz')
scope.source.expects(:type).returns('definition')
- expect {
- subject.call []
- }.to raise_error Puppet::ParseError, /Definition foo::baz is private/
+
+ is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /Definition foo::baz is private/)
end
end
end
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/dig44_spec.rb b/spec/functions/dig44_spec.rb
index fd451ff..4f7408d 100644
--- a/spec/functions/dig44_spec.rb
+++ b/spec/functions/dig44_spec.rb
@@ -1,44 +1,105 @@
require 'spec_helper'
describe 'dig44' do
- it "should exist" do
- expect(Puppet::Parser::Functions.function("dig44")).to eq("function_dig44")
+
+ let(:data) do
+ {
+ 'a' => {
+ 'g' => '2',
+ 'e' => [
+ 'f0',
+ 'f1',
+ {
+ 'x' => {
+ 'y' => 'z'
+ }
+ },
+ 'f3',
+ ]
+ },
+ 'b' => true,
+ 'c' => false,
+ 'd' => '1',
+ 'e' => :undef,
+ 'f' => nil,
+ }
end
- it "should raise a ParseError if there are less than 2 arguments" do
- expect { scope.function_dig44([]) }.to raise_error(Puppet::ParseError)
- end
+ context 'single values' do
+ it 'should exist' do
+ is_expected.not_to be_nil
+ end
- it "should raise a ParseError if the first argument isn't a hash or array" do
- expect { scope.function_dig44(['bad', []]) }.to raise_error(Puppet::ParseError)
- end
+ it 'should require two arguments' do
+ is_expected.to run.with_params().and_raise_error(ArgumentError)
+ end
- it "should raise a ParseError if the second argument isn't an array" do
- expect { scope.function_dig44([{}, 'bad']) }.to raise_error(Puppet::ParseError)
- end
+ it 'should fail if the data is not a structure' do
+ is_expected.to run.with_params('test', []).and_raise_error(Puppet::Error)
+ end
- it "should return an empty hash when given empty parameters" do
- result = scope.function_dig44([{}, []])
- expect(result).to(eq({}))
- end
+ it 'should fail if the path is not an array' do
+ is_expected.to run.with_params({}, '').and_raise_error(Puppet::Error)
+ end
- it "should return value when given simple hash" do
- result = scope.function_dig44([{"a" => "b"}, ["a"]])
- expect(result).to(eq("b"))
- end
+ it 'should return the value if the value is string' do
+ is_expected.to run.with_params(data, ['d'], 'default').and_return('1')
+ end
- it "should find hash values two levels deep" do
- result = scope.function_dig44([{"a" => {"b" => "c"}}, ["a", "b"]])
- expect(result).to(eq("c"))
- end
+ it 'should return true if the value is true' do
+ is_expected.to run.with_params(data, ['b'], 'default').and_return(true)
+ end
- it "should return default value if nothing was found" do
- result = scope.function_dig44([{}, ["a", "b"], "d"])
- expect(result).to(eq("d"))
+ it 'should return false if the value is false' do
+ is_expected.to run.with_params(data, ['c'], 'default').and_return(false)
+ end
+
+ it 'should return the default if the value is nil' do
+ is_expected.to run.with_params(data, ['f'], 'default').and_return('default')
+ end
+
+ it 'should return the default if the value is :undef (same as nil)' do
+ is_expected.to run.with_params(data, ['e'], 'default').and_return('default')
+ end
+
+ it 'should return the default if the path is not found' do
+ is_expected.to run.with_params(data, ['missing'], 'default').and_return('default')
+ end
end
- it "should work on booleans as well as strings" do
- result = scope.function_dig44([{"a" => false}, ["a"]])
- expect(result).to(eq(false))
+ context 'structure values' do
+
+ it 'should be able to extract a deeply nested hash value' do
+ is_expected.to run.with_params(data, %w(a g), 'default').and_return('2')
+ end
+
+ it 'should return the default value if the path is too long' do
+ is_expected.to run.with_params(data, %w(a g c d), 'default').and_return('default')
+ end
+
+ it 'should support an array index (number) in the path' do
+ is_expected.to run.with_params(data, ['a', 'e', 1], 'default').and_return('f1')
+ end
+
+ it 'should support an array index (string) in the path' do
+ is_expected.to run.with_params(data, %w(a e 1), 'default').and_return('f1')
+ end
+
+ it 'should return the default value if an array index is not a number' do
+ is_expected.to run.with_params(data, %w(a b c), 'default').and_return('default')
+ end
+
+ it 'should return the default value if and index is out of array length' do
+ is_expected.to run.with_params(data, %w(a e 5), 'default').and_return('default')
+ end
+
+ it 'should be able to path though both arrays and hashes' do
+ is_expected.to run.with_params(data, %w(a e 2 x y), 'default').and_return('z')
+ end
+
+ it 'should return "nil" if value is not found and no default value is provided' do
+ is_expected.to run.with_params(data, %w(a 1)).and_return(nil)
+ end
+
end
end
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_legacy_spec.rb b/spec/functions/validate_legacy_spec.rb
new file mode 100644
index 0000000..45089ef
--- /dev/null
+++ b/spec/functions/validate_legacy_spec.rb
@@ -0,0 +1,68 @@
+require 'spec_helper'
+
+if Puppet.version.to_f >= 4.0
+ describe 'validate_legacy' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(ArgumentError) }
+
+ describe 'when passing the type assertion and passing the previous validation' do
+ before do
+ scope.expects(:function_validate_foo).with([5]).once
+ Puppet.expects(:notice).never
+ end
+ it 'passes without notice' do
+ is_expected.to run.with_params('Integer', 'validate_foo', 5)
+ end
+ end
+
+ describe 'when passing the type assertion and failing the previous validation' do
+ before do
+ scope.expects(:function_validate_foo).with([5]).raises(Puppet::ParseError, 'foo').once
+ Puppet.expects(:notice).with(includes('Accepting previously invalid value for target type'))
+ end
+ it 'passes with a notice about newly accepted value' do
+ is_expected.to run.with_params('Integer', 'validate_foo', 5)
+ end
+ end
+
+ describe 'when failing the type assertion and passing the previous validation' do
+ before do
+ scope.expects(:function_validate_foo).with(['5']).once
+ subject.func.expects(:call_function).with('deprecation', 'validate_legacy', includes('expected an Integer value')).once
+ end
+ it 'passes with a deprecation message' do
+ is_expected.to run.with_params('Integer', 'validate_foo', '5')
+ end
+ end
+
+ describe 'when failing the type assertion and failing the previous validation' do
+ before do
+ scope.expects(:function_validate_foo).with(['5']).raises(Puppet::ParseError, 'foo').once
+ subject.func.expects(:call_function).with('fail', includes('expected an Integer value')).once
+ end
+ it 'fails with a helpful message' do
+ is_expected.to run.with_params('Integer', 'validate_foo', '5')
+ end
+ end
+
+ describe 'when passing in undef' do
+ before do
+ scope.expects(:function_validate_foo).with([:undef]).once
+ Puppet.expects(:notice).never
+ end
+ it 'works' do
+ is_expected.to run.with_params('Optional[Integer]', 'validate_foo', :undef)
+ end
+ end
+
+ describe 'when passing in multiple arguments' do
+ before do
+ scope.expects(:function_validate_foo).with([:undef, 1, 'foo']).once
+ Puppet.expects(:notice).never
+ end
+ it 'passes with a deprecation message' do
+ is_expected.to run.with_params('Optional[Integer]', 'validate_foo', :undef, 1, 'foo')
+ end
+ 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..2fa9ddd 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
@@ -23,22 +28,6 @@ describe 'validate_re' do
end
describe 'invalid inputs' do
- it {
- pending('should implement stricter type checking')
- is_expected.to run.with_params([], '').and_raise_error(Puppet::ParseError, /is not a String/)
- }
- it {
- pending('should implement stricter type checking')
- is_expected.to run.with_params('', {}).and_raise_error(Puppet::ParseError, /is not an Array/)
- }
- it {
- pending('should implement stricter type checking')
- is_expected.to run.with_params('', '', []).and_raise_error(Puppet::ParseError, /is not a String/)
- }
- it {
- pending('should implement stricter type checking')
- is_expected.to run.with_params(nil, nil).and_raise_error(Puppet::ParseError, /is not a String/)
- }
it { is_expected.to run.with_params('', []).and_raise_error(Puppet::ParseError, /does not match/) }
it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError, /does not match/) }
it { is_expected.to run.with_params('', 'two').and_raise_error(Puppet::ParseError, /does not match/) }
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