diff options
author | David Schmitt <david.schmitt@puppet.com> | 2016-09-21 12:13:34 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-21 12:13:34 +0100 |
commit | e94beb5bd189296ac3dade603c1b45ac7183ec21 (patch) | |
tree | 48aae9abafbbe893ad8919ed87826151709d6910 | |
parent | 66830ac66ac4d435c56c5f3fc93592c32c087726 (diff) | |
parent | 0ec7ffa5c086c8a1c6e871b086299dd1953fa8ba (diff) |
Merge pull request #654 from HelenCampbell/puppet4Dep
Ensure validate functions use Puppet 4 deprecation
-rw-r--r-- | lib/puppet/functions/validate_absolute_path.rb | 3 | ||||
-rw-r--r-- | lib/puppet/functions/validate_array.rb | 3 | ||||
-rw-r--r-- | lib/puppet/functions/validate_bool.rb | 3 | ||||
-rw-r--r-- | lib/puppet/functions/validate_hash.rb | 3 | ||||
-rw-r--r-- | lib/puppet/functions/validate_integer.rb | 3 | ||||
-rw-r--r-- | lib/puppet/functions/validate_ip_address.rb | 3 | ||||
-rw-r--r-- | lib/puppet/functions/validate_ipv4_address.rb | 3 | ||||
-rw-r--r-- | lib/puppet/functions/validate_ipv6_address.rb | 3 | ||||
-rw-r--r-- | lib/puppet/functions/validate_numeric.rb | 3 | ||||
-rw-r--r-- | lib/puppet/functions/validate_re.rb | 3 | ||||
-rw-r--r-- | lib/puppet/functions/validate_string.rb | 3 | ||||
-rw-r--r-- | lib/puppet_x/puppetlabs/stdlib/deprecation_gen.rb | 21 | ||||
-rwxr-xr-x | spec/acceptance/validate_array_spec.rb | 16 | ||||
-rwxr-xr-x | spec/acceptance/validate_bool_spec.rb | 16 | ||||
-rwxr-xr-x | spec/acceptance/validate_hash_spec.rb | 16 |
15 files changed, 78 insertions, 24 deletions
diff --git a/lib/puppet/functions/validate_absolute_path.rb b/lib/puppet/functions/validate_absolute_path.rb new file mode 100644 index 0000000..5ae9d29 --- /dev/null +++ b/lib/puppet/functions/validate_absolute_path.rb @@ -0,0 +1,3 @@ +require 'puppet_x/puppetlabs/stdlib/deprecation_gen' +PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_absolute_path", "Stdlib::Compat::Absolute_Path") +# Puppet::Functions.create_function diff --git a/lib/puppet/functions/validate_array.rb b/lib/puppet/functions/validate_array.rb new file mode 100644 index 0000000..9155784 --- /dev/null +++ b/lib/puppet/functions/validate_array.rb @@ -0,0 +1,3 @@ +require 'puppet_x/puppetlabs/stdlib/deprecation_gen' +PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_array", "Stdlib::Compat::Array") +# Puppet::Functions.create_function diff --git a/lib/puppet/functions/validate_bool.rb b/lib/puppet/functions/validate_bool.rb new file mode 100644 index 0000000..10f6edf --- /dev/null +++ b/lib/puppet/functions/validate_bool.rb @@ -0,0 +1,3 @@ +require 'puppet_x/puppetlabs/stdlib/deprecation_gen' +PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_bool", "Stdlib::Compat::Bool") +# Puppet::Functions.create_function diff --git a/lib/puppet/functions/validate_hash.rb b/lib/puppet/functions/validate_hash.rb new file mode 100644 index 0000000..5349664 --- /dev/null +++ b/lib/puppet/functions/validate_hash.rb @@ -0,0 +1,3 @@ +require 'puppet_x/puppetlabs/stdlib/deprecation_gen' +PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_hash", "Stdlib::Compat::Hash") +# Puppet::Functions.create_function diff --git a/lib/puppet/functions/validate_integer.rb b/lib/puppet/functions/validate_integer.rb new file mode 100644 index 0000000..2c4645d --- /dev/null +++ b/lib/puppet/functions/validate_integer.rb @@ -0,0 +1,3 @@ +require 'puppet_x/puppetlabs/stdlib/deprecation_gen' +PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_integer", "Stdlib::Compat::Integer") +# Puppet::Functions.create_function diff --git a/lib/puppet/functions/validate_ip_address.rb b/lib/puppet/functions/validate_ip_address.rb new file mode 100644 index 0000000..15a710e --- /dev/null +++ b/lib/puppet/functions/validate_ip_address.rb @@ -0,0 +1,3 @@ +require 'puppet_x/puppetlabs/stdlib/deprecation_gen' +PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_ip_address", "Stdlib::Compat::Ip_Address") +# Puppet::Functions.create_function diff --git a/lib/puppet/functions/validate_ipv4_address.rb b/lib/puppet/functions/validate_ipv4_address.rb new file mode 100644 index 0000000..8e1bc59 --- /dev/null +++ b/lib/puppet/functions/validate_ipv4_address.rb @@ -0,0 +1,3 @@ +require 'puppet_x/puppetlabs/stdlib/deprecation_gen' +PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_ipv4_address", "Stdlib::Compat::Ipv4_Address") +# Puppet::Functions.create_function diff --git a/lib/puppet/functions/validate_ipv6_address.rb b/lib/puppet/functions/validate_ipv6_address.rb new file mode 100644 index 0000000..865648a --- /dev/null +++ b/lib/puppet/functions/validate_ipv6_address.rb @@ -0,0 +1,3 @@ +require 'puppet_x/puppetlabs/stdlib/deprecation_gen' +PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_ipv6_address", "Stdlib::Compat::Ipv6_address") +# Puppet::Functions.create_function diff --git a/lib/puppet/functions/validate_numeric.rb b/lib/puppet/functions/validate_numeric.rb new file mode 100644 index 0000000..0c2e1f2 --- /dev/null +++ b/lib/puppet/functions/validate_numeric.rb @@ -0,0 +1,3 @@ +require 'puppet_x/puppetlabs/stdlib/deprecation_gen' +PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_numeric", "Stdlib::Compat::Numeric") +# Puppet::Functions.create_function diff --git a/lib/puppet/functions/validate_re.rb b/lib/puppet/functions/validate_re.rb new file mode 100644 index 0000000..d63ed42 --- /dev/null +++ b/lib/puppet/functions/validate_re.rb @@ -0,0 +1,3 @@ +require 'puppet_x/puppetlabs/stdlib/deprecation_gen' +PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_re", "Stdlib::Compat::Re") +# Puppet::Functions.create_function diff --git a/lib/puppet/functions/validate_string.rb b/lib/puppet/functions/validate_string.rb new file mode 100644 index 0000000..a196f43 --- /dev/null +++ b/lib/puppet/functions/validate_string.rb @@ -0,0 +1,3 @@ +require 'puppet_x/puppetlabs/stdlib/deprecation_gen' +PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_string", "Stdlib::Compat::String") +# Puppet::Functions.create_function diff --git a/lib/puppet_x/puppetlabs/stdlib/deprecation_gen.rb b/lib/puppet_x/puppetlabs/stdlib/deprecation_gen.rb new file mode 100644 index 0000000..a3d830b --- /dev/null +++ b/lib/puppet_x/puppetlabs/stdlib/deprecation_gen.rb @@ -0,0 +1,21 @@ +# Creates a Puppet 4 function for the corresponding puppet 3 validate function, who's name will be passed as an argument, alongside the type for deprecation output purposes. +module PuppetX + module Puppetlabs + module Stdlib + def self.deprecation_gen(funct, type) + Puppet::Functions.create_function(funct, Puppet::Functions::InternalFunction) do + @@funct = funct + @@type = type + dispatch :deprecation_gen do + scope_param + optional_repeated_param 'Any', :args + end + def deprecation_gen(scope, *args) + call_function('deprecation', 'puppet_3_type_check', "This method is deprecated, please use the stdlib validate_legacy function, with #{@@type}. There is further documentation for validate_legacy function in the README.") + scope.send("function_#{@@funct}", args) + end + end + end + end + end +end diff --git a/spec/acceptance/validate_array_spec.rb b/spec/acceptance/validate_array_spec.rb index b53e98c..2f549d5 100755 --- a/spec/acceptance/validate_array_spec.rb +++ b/spec/acceptance/validate_array_spec.rb @@ -20,14 +20,14 @@ describe 'validate_array function', :unless => UNSUPPORTED_PLATFORMS.include?(fa apply_manifest(pp, :catch_failures => true) end - it 'validates a non-array' do - { - %{validate_array({'a' => 'hash' })} => "Hash", - %{validate_array('string')} => "String", - %{validate_array(false)} => "FalseClass", - %{validate_array(undef)} => "String" - }.each do |pp,type| - expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/a #{type}/) + [ + %{validate_array({'a' => 'hash' })}, + %{validate_array('string')}, + %{validate_array(false)}, + %{validate_array(undef)} + ].each do |pp| + it "rejects #{pp.inspect}" do + expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/is not an Array\. It looks to be a/) end end end diff --git a/spec/acceptance/validate_bool_spec.rb b/spec/acceptance/validate_bool_spec.rb index c837f08..5c52d0f 100755 --- a/spec/acceptance/validate_bool_spec.rb +++ b/spec/acceptance/validate_bool_spec.rb @@ -20,14 +20,14 @@ describe 'validate_bool function', :unless => UNSUPPORTED_PLATFORMS.include?(fac apply_manifest(pp, :catch_failures => true) end - it 'validates a non-bool' do - { - %{validate_bool('true')} => "String", - %{validate_bool('false')} => "String", - %{validate_bool([true])} => "Array", - %{validate_bool(undef)} => "String", - }.each do |pp,type| - expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/a #{type}/) + [ + %{validate_bool('true')}, + %{validate_bool('false')}, + %{validate_bool([true])}, + %{validate_bool(undef)} + ].each do |pp| + it "rejects #{pp.inspect}" do + expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/is not a boolean\. It looks to be a/) end end end diff --git a/spec/acceptance/validate_hash_spec.rb b/spec/acceptance/validate_hash_spec.rb index 52fb615..637df0a 100755 --- a/spec/acceptance/validate_hash_spec.rb +++ b/spec/acceptance/validate_hash_spec.rb @@ -20,14 +20,14 @@ describe 'validate_hash function', :unless => UNSUPPORTED_PLATFORMS.include?(fac apply_manifest(pp, :catch_failures => true) end - it 'validates a non-hash' do - { - %{validate_hash('{ "not" => "hash" }')} => "String", - %{validate_hash('string')} => "String", - %{validate_hash(["array"])} => "Array", - %{validate_hash(undef)} => "String", - }.each do |pp,type| - expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/a #{type}/) + [ + %{validate_hash('{ "not" => "hash" }')}, + %{validate_hash('string')}, + %{validate_hash(["array"])}, + %{validate_hash(undef)} + ].each do |pp| + it "rejects #{pp.inspect}" do + expect(apply_manifest(pp, :expect_failures => true).stderr).to match(//) end end end |