Skip to content

Ensure validate functions use Puppet 4 deprecation #659

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/puppet/functions/validate_absolute_path.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions lib/puppet/functions/validate_array.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions lib/puppet/functions/validate_bool.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions lib/puppet/functions/validate_hash.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions lib/puppet/functions/validate_integer.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions lib/puppet/functions/validate_ip_address.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions lib/puppet/functions/validate_ipv4_address.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions lib/puppet/functions/validate_ipv6_address.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions lib/puppet/functions/validate_numeric.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions lib/puppet/functions/validate_re.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions lib/puppet/functions/validate_string.rb
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions lib/puppet_x/puppetlabs/stdlib/deprecation_gen.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 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
dispatch :deprecation_gen do
scope_param
optional_repeated_param 'Any', :args
end
define_method 'deprecation_gen' do |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
16 changes: 8 additions & 8 deletions spec/acceptance/validate_array_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@

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
Expand Down
16 changes: 8 additions & 8 deletions spec/acceptance/validate_bool_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@

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
Expand Down
16 changes: 8 additions & 8 deletions spec/acceptance/validate_hash_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@

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
Expand Down
2 changes: 1 addition & 1 deletion spec/functions/deprecation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
end
else
describe 'deprecation' do
after(:context) do
after(:all) do
ENV.delete('STDLIB_LOG_DEPRECATIONS')
end
ENV['STDLIB_LOG_DEPRECATIONS'] = "true"
Expand Down
2 changes: 1 addition & 1 deletion spec/functions/is_array_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
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
after(:all) do
ENV.delete('STDLIB_LOG_DEPRECATIONS')
end
# Checking for deprecation warning, which should only be provoked when the env variable for it is set.
Expand Down
2 changes: 1 addition & 1 deletion spec/functions/is_bool_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
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
after(:all) do
ENV.delete('STDLIB_LOG_DEPRECATIONS')
end
# Checking for deprecation warning, which should only be provoked when the env variable for it is set.
Expand Down
2 changes: 1 addition & 1 deletion spec/functions/is_float_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
end

context 'Checking for deprecation warning' do
after(:context) do
after(:all) do
ENV.delete('STDLIB_LOG_DEPRECATIONS')
end
# Checking for deprecation warning, which should only be provoked when the env variable for it is set.
Expand Down
2 changes: 1 addition & 1 deletion spec/functions/is_integer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
it { is_expected.to run.with_params('0001234').and_return(false) }

context 'Checking for deprecation warning' do
after(:context) do
after(:all) do
ENV.delete('STDLIB_LOG_DEPRECATIONS')
end
# Checking for deprecation warning, which should only be provoked when the env variable for it is set.
Expand Down
2 changes: 1 addition & 1 deletion spec/functions/is_ip_address_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
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
after(:all) do
ENV.delete('STDLIB_LOG_DEPRECATIONS')
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/functions/is_ipv4_address_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
it { is_expected.to run.with_params('one').and_return(false) }

context 'Checking for deprecation warning', if: Puppet.version.to_f < 4.0 do
after(:context) do
after(:all) do
ENV.delete('STDLIB_LOG_DEPRECATIONS')
end
# Checking for deprecation warning, which should only be provoked when the env variable for it is set.
Expand Down
2 changes: 1 addition & 1 deletion spec/functions/is_ipv6_address_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
it { is_expected.to run.with_params('one').and_return(false) }

context 'Checking for deprecation warning', if: Puppet.version.to_f < 4.0 do
after(:context) do
after(:all) do
ENV.delete('STDLIB_LOG_DEPRECATIONS')
end
# Checking for deprecation warning, which should only be provoked when the env variable for it is set.
Expand Down
2 changes: 1 addition & 1 deletion spec/functions/is_numeric_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
it { is_expected.to run.with_params(' - 1234').and_return(false) }

context 'Checking for deprecation warning' do
after(:context) do
after(:all) do
ENV.delete('STDLIB_LOG_DEPRECATIONS')
end
# Checking for deprecation warning, which should only be provoked when the env variable for it is set.
Expand Down
2 changes: 1 addition & 1 deletion spec/functions/is_string_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
it { is_expected.to run.with_params('0001234').and_return(true) }

context 'Checking for deprecation warning' do
after(:context) do
after(:all) do
ENV.delete('STDLIB_LOG_DEPRECATIONS')
end
# Checking for deprecation warning, which should only be provoked when the env variable for it is set.
Expand Down
2 changes: 1 addition & 1 deletion spec/functions/validate_absolute_path_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'

describe 'validate_absolute_path' do
after(:context) do
after(:all) do
ENV.delete('STDLIB_LOG_DEPRECATIONS')
end

Expand Down
2 changes: 1 addition & 1 deletion spec/functions/validate_array_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe 'validate_array' do

describe 'signature validation' do
after(:context) do
after(:all) do
ENV.delete('STDLIB_LOG_DEPRECATIONS')
end
it { is_expected.not_to eq(nil) }
Expand Down
2 changes: 1 addition & 1 deletion spec/functions/validate_bool_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'

describe 'validate_bool' do
after(:context) do
after(:all) do
ENV.delete('STDLIB_LOG_DEPRECATIONS')
end

Expand Down
2 changes: 1 addition & 1 deletion spec/functions/validate_hash_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }

describe 'check for deprecation warning' do
after(:context) do
after(:all) do
ENV.delete('STDLIB_LOG_DEPRECATIONS')
end
# Checking for deprecation warning
Expand Down
2 changes: 1 addition & 1 deletion spec/functions/validate_integer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'

describe 'validate_integer' do
after(:context) do
after(:all) do
ENV.delete('STDLIB_LOG_DEPRECATIONS')
end

Expand Down
2 changes: 1 addition & 1 deletion spec/functions/validate_ip_address_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
it { is_expected.to run.with_params('fe80::a00:27ff:fe94:44d6/64') }

context 'Checking for deprecation warning', if: Puppet.version.to_f < 4.0 do
after(:context) do
after(:all) do
ENV.delete('STDLIB_LOG_DEPRECATIONS')
end
# Checking for deprecation warning, which should only be provoked when the env variable for it is set.
Expand Down
2 changes: 1 addition & 1 deletion spec/functions/validate_ipv4_address_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
end

context 'Checking for deprecation warning', if: Puppet.version.to_f < 4.0 do
after(:context) do
after(:all) do
ENV.delete('STDLIB_LOG_DEPRECATIONS')
end
# Checking for deprecation warning, which should only be provoked when the env variable for it is set.
Expand Down
2 changes: 1 addition & 1 deletion spec/functions/validate_ipv6_address_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
end

context 'Checking for deprecation warning', if: Puppet.version.to_f < 4.0 do
after(:context) do
after(:all) do
ENV.delete('STDLIB_LOG_DEPRECATIONS')
end
# Checking for deprecation warning, which should only be provoked when the env variable for it is set.
Expand Down
2 changes: 1 addition & 1 deletion spec/functions/validate_numeric_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'

describe 'validate_numeric' do
after(:context) do
after(:all) do
ENV.delete('STDLIB_LOG_DEPRECATIONS')
end

Expand Down
2 changes: 1 addition & 1 deletion spec/functions/validate_re_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'

describe 'validate_re' do
after(:context) do
after(:all) do
ENV.delete('STDLIB_LOG_DEPRECATIONS')
end

Expand Down
2 changes: 1 addition & 1 deletion spec/functions/validate_slength_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'

describe 'validate_slength' do
after(:context) do
after(:all) do
ENV.delete('STDLIB_LOG_DEPRECATIONS')
end

Expand Down
2 changes: 1 addition & 1 deletion spec/functions/validate_string_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'

describe 'validate_string' do
after(:context) do
after(:all) do
ENV.delete('STDLIB_LOG_DEPRECATIONS')
end

Expand Down