Skip to content

Commit f01c64e

Browse files
author
Helen Campbell
committed
Ensure validate functions use Puppet 4 deprecation
1 parent 96af506 commit f01c64e

37 files changed

+98
-46
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require 'puppet_x/puppetlabs/stdlib/deprecation_gen'
2+
PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_absolute_path", "Stdlib::Compat::Absolute_Path")
3+
# Puppet::Functions.create_function
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require 'puppet_x/puppetlabs/stdlib/deprecation_gen'
2+
PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_array", "Stdlib::Compat::Array")
3+
# Puppet::Functions.create_function

lib/puppet/functions/validate_bool.rb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require 'puppet_x/puppetlabs/stdlib/deprecation_gen'
2+
PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_bool", "Stdlib::Compat::Bool")
3+
# Puppet::Functions.create_function

lib/puppet/functions/validate_hash.rb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require 'puppet_x/puppetlabs/stdlib/deprecation_gen'
2+
PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_hash", "Stdlib::Compat::Hash")
3+
# Puppet::Functions.create_function
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require 'puppet_x/puppetlabs/stdlib/deprecation_gen'
2+
PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_integer", "Stdlib::Compat::Integer")
3+
# Puppet::Functions.create_function
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require 'puppet_x/puppetlabs/stdlib/deprecation_gen'
2+
PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_ip_address", "Stdlib::Compat::Ip_Address")
3+
# Puppet::Functions.create_function
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require 'puppet_x/puppetlabs/stdlib/deprecation_gen'
2+
PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_ipv4_address", "Stdlib::Compat::Ipv4_Address")
3+
# Puppet::Functions.create_function
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require 'puppet_x/puppetlabs/stdlib/deprecation_gen'
2+
PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_ipv6_address", "Stdlib::Compat::Ipv6_address")
3+
# Puppet::Functions.create_function
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require 'puppet_x/puppetlabs/stdlib/deprecation_gen'
2+
PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_numeric", "Stdlib::Compat::Numeric")
3+
# Puppet::Functions.create_function

lib/puppet/functions/validate_re.rb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require 'puppet_x/puppetlabs/stdlib/deprecation_gen'
2+
PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_re", "Stdlib::Compat::Re")
3+
# Puppet::Functions.create_function
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require 'puppet_x/puppetlabs/stdlib/deprecation_gen'
2+
PuppetX::Puppetlabs::Stdlib.deprecation_gen("validate_string", "Stdlib::Compat::String")
3+
# Puppet::Functions.create_function
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# 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.
2+
module PuppetX
3+
module Puppetlabs
4+
module Stdlib
5+
def self.deprecation_gen(funct, type)
6+
Puppet::Functions.create_function(funct, Puppet::Functions::InternalFunction) do
7+
dispatch :deprecation_gen do
8+
scope_param
9+
optional_repeated_param 'Any', :args
10+
end
11+
define_method 'deprecation_gen' do |scope, *args|
12+
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.")
13+
scope.send("function_#{funct}", args)
14+
end
15+
end
16+
end
17+
end
18+
end
19+
end

spec/acceptance/validate_array_spec.rb

+8-8
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020

2121
apply_manifest(pp, :catch_failures => true)
2222
end
23-
it 'validates a non-array' do
24-
{
25-
%{validate_array({'a' => 'hash' })} => "Hash",
26-
%{validate_array('string')} => "String",
27-
%{validate_array(false)} => "FalseClass",
28-
%{validate_array(undef)} => "String"
29-
}.each do |pp,type|
30-
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/a #{type}/)
23+
[
24+
%{validate_array({'a' => 'hash' })},
25+
%{validate_array('string')},
26+
%{validate_array(false)},
27+
%{validate_array(undef)}
28+
].each do |pp|
29+
it "rejects #{pp.inspect}" do
30+
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/is not an Array\. It looks to be a/)
3131
end
3232
end
3333
end

spec/acceptance/validate_bool_spec.rb

+8-8
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020

2121
apply_manifest(pp, :catch_failures => true)
2222
end
23-
it 'validates a non-bool' do
24-
{
25-
%{validate_bool('true')} => "String",
26-
%{validate_bool('false')} => "String",
27-
%{validate_bool([true])} => "Array",
28-
%{validate_bool(undef)} => "String",
29-
}.each do |pp,type|
30-
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/a #{type}/)
23+
[
24+
%{validate_bool('true')},
25+
%{validate_bool('false')},
26+
%{validate_bool([true])},
27+
%{validate_bool(undef)}
28+
].each do |pp|
29+
it "rejects #{pp.inspect}" do
30+
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/is not a boolean\. It looks to be a/)
3131
end
3232
end
3333
end

spec/acceptance/validate_hash_spec.rb

+8-8
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020

2121
apply_manifest(pp, :catch_failures => true)
2222
end
23-
it 'validates a non-hash' do
24-
{
25-
%{validate_hash('{ "not" => "hash" }')} => "String",
26-
%{validate_hash('string')} => "String",
27-
%{validate_hash(["array"])} => "Array",
28-
%{validate_hash(undef)} => "String",
29-
}.each do |pp,type|
30-
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/a #{type}/)
23+
[
24+
%{validate_hash('{ "not" => "hash" }')},
25+
%{validate_hash('string')},
26+
%{validate_hash(["array"])},
27+
%{validate_hash(undef)}
28+
].each do |pp|
29+
it "rejects #{pp.inspect}" do
30+
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(//)
3131
end
3232
end
3333
end

spec/functions/deprecation_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
end
4343
else
4444
describe 'deprecation' do
45-
after(:context) do
45+
after(:all) do
4646
ENV.delete('STDLIB_LOG_DEPRECATIONS')
4747
end
4848
ENV['STDLIB_LOG_DEPRECATIONS'] = "true"

spec/functions/is_array_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
it { is_expected.to run.with_params(1).and_return(false) }
1919
it { is_expected.to run.with_params({}).and_return(false) }
2020
context 'Checking for deprecation warning' do
21-
after(:context) do
21+
after(:all) do
2222
ENV.delete('STDLIB_LOG_DEPRECATIONS')
2323
end
2424
# Checking for deprecation warning, which should only be provoked when the env variable for it is set.

spec/functions/is_bool_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
it { is_expected.to run.with_params('true').and_return(false) }
1515
it { is_expected.to run.with_params('false').and_return(false) }
1616
context 'Checking for deprecation warning' do
17-
after(:context) do
17+
after(:all) do
1818
ENV.delete('STDLIB_LOG_DEPRECATIONS')
1919
end
2020
# Checking for deprecation warning, which should only be provoked when the env variable for it is set.

spec/functions/is_float_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
end
2424

2525
context 'Checking for deprecation warning' do
26-
after(:context) do
26+
after(:all) do
2727
ENV.delete('STDLIB_LOG_DEPRECATIONS')
2828
end
2929
# Checking for deprecation warning, which should only be provoked when the env variable for it is set.

spec/functions/is_integer_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
it { is_expected.to run.with_params('0001234').and_return(false) }
2727

2828
context 'Checking for deprecation warning' do
29-
after(:context) do
29+
after(:all) do
3030
ENV.delete('STDLIB_LOG_DEPRECATIONS')
3131
end
3232
# Checking for deprecation warning, which should only be provoked when the env variable for it is set.

spec/functions/is_ip_address_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
scope.expects(:warning).with(includes('This method is deprecated')).never
3434
is_expected.to run.with_params('1.2.3.4').and_return(true)
3535
end
36-
after(:context) do
36+
after(:all) do
3737
ENV.delete('STDLIB_LOG_DEPRECATIONS')
3838
end
3939
end

spec/functions/is_ipv4_address_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
it { is_expected.to run.with_params('one').and_return(false) }
1313

1414
context 'Checking for deprecation warning', if: Puppet.version.to_f < 4.0 do
15-
after(:context) do
15+
after(:all) do
1616
ENV.delete('STDLIB_LOG_DEPRECATIONS')
1717
end
1818
# Checking for deprecation warning, which should only be provoked when the env variable for it is set.

spec/functions/is_ipv6_address_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
it { is_expected.to run.with_params('one').and_return(false) }
1313

1414
context 'Checking for deprecation warning', if: Puppet.version.to_f < 4.0 do
15-
after(:context) do
15+
after(:all) do
1616
ENV.delete('STDLIB_LOG_DEPRECATIONS')
1717
end
1818
# Checking for deprecation warning, which should only be provoked when the env variable for it is set.

spec/functions/is_numeric_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
it { is_expected.to run.with_params(' - 1234').and_return(false) }
3030

3131
context 'Checking for deprecation warning' do
32-
after(:context) do
32+
after(:all) do
3333
ENV.delete('STDLIB_LOG_DEPRECATIONS')
3434
end
3535
# Checking for deprecation warning, which should only be provoked when the env variable for it is set.

spec/functions/is_string_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
it { is_expected.to run.with_params('0001234').and_return(true) }
2929

3030
context 'Checking for deprecation warning' do
31-
after(:context) do
31+
after(:all) do
3232
ENV.delete('STDLIB_LOG_DEPRECATIONS')
3333
end
3434
# Checking for deprecation warning, which should only be provoked when the env variable for it is set.

spec/functions/validate_absolute_path_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'spec_helper'
22

33
describe 'validate_absolute_path' do
4-
after(:context) do
4+
after(:all) do
55
ENV.delete('STDLIB_LOG_DEPRECATIONS')
66
end
77

spec/functions/validate_array_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
describe 'validate_array' do
44

55
describe 'signature validation' do
6-
after(:context) do
6+
after(:all) do
77
ENV.delete('STDLIB_LOG_DEPRECATIONS')
88
end
99
it { is_expected.not_to eq(nil) }

spec/functions/validate_bool_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'spec_helper'
22

33
describe 'validate_bool' do
4-
after(:context) do
4+
after(:all) do
55
ENV.delete('STDLIB_LOG_DEPRECATIONS')
66
end
77

spec/functions/validate_hash_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
77

88
describe 'check for deprecation warning' do
9-
after(:context) do
9+
after(:all) do
1010
ENV.delete('STDLIB_LOG_DEPRECATIONS')
1111
end
1212
# Checking for deprecation warning

spec/functions/validate_integer_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'spec_helper'
22

33
describe 'validate_integer' do
4-
after(:context) do
4+
after(:all) do
55
ENV.delete('STDLIB_LOG_DEPRECATIONS')
66
end
77

spec/functions/validate_ip_address_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
it { is_expected.to run.with_params('fe80::a00:27ff:fe94:44d6/64') }
2323

2424
context 'Checking for deprecation warning', if: Puppet.version.to_f < 4.0 do
25-
after(:context) do
25+
after(:all) do
2626
ENV.delete('STDLIB_LOG_DEPRECATIONS')
2727
end
2828
# Checking for deprecation warning, which should only be provoked when the env variable for it is set.

spec/functions/validate_ipv4_address_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
end
99

1010
context 'Checking for deprecation warning', if: Puppet.version.to_f < 4.0 do
11-
after(:context) do
11+
after(:all) do
1212
ENV.delete('STDLIB_LOG_DEPRECATIONS')
1313
end
1414
# Checking for deprecation warning, which should only be provoked when the env variable for it is set.

spec/functions/validate_ipv6_address_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
end
99

1010
context 'Checking for deprecation warning', if: Puppet.version.to_f < 4.0 do
11-
after(:context) do
11+
after(:all) do
1212
ENV.delete('STDLIB_LOG_DEPRECATIONS')
1313
end
1414
# Checking for deprecation warning, which should only be provoked when the env variable for it is set.

spec/functions/validate_numeric_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'spec_helper'
22

33
describe 'validate_numeric' do
4-
after(:context) do
4+
after(:all) do
55
ENV.delete('STDLIB_LOG_DEPRECATIONS')
66
end
77

spec/functions/validate_re_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'spec_helper'
22

33
describe 'validate_re' do
4-
after(:context) do
4+
after(:all) do
55
ENV.delete('STDLIB_LOG_DEPRECATIONS')
66
end
77

spec/functions/validate_slength_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'spec_helper'
22

33
describe 'validate_slength' do
4-
after(:context) do
4+
after(:all) do
55
ENV.delete('STDLIB_LOG_DEPRECATIONS')
66
end
77

spec/functions/validate_string_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'spec_helper'
22

33
describe 'validate_string' do
4-
after(:context) do
4+
after(:all) do
55
ENV.delete('STDLIB_LOG_DEPRECATIONS')
66
end
77

0 commit comments

Comments
 (0)