From 22fbe723acd22ae3491c41beeacbc76853c6820e Mon Sep 17 00:00:00 2001 From: tphoney Date: Mon, 8 Aug 2016 17:35:13 +0100 Subject: (modules-3532) deprecate string type checks --- spec/aliases/string_spec.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 spec/aliases/string_spec.rb (limited to 'spec/aliases/string_spec.rb') diff --git a/spec/aliases/string_spec.rb b/spec/aliases/string_spec.rb new file mode 100644 index 0000000..8e01d55 --- /dev/null +++ b/spec/aliases/string_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper' + +if Puppet.version.to_f >= 4.0 + describe 'test::string', type: :class do + describe 'accepts strings' do + [ + '', + 'one', + ].each do |value| + describe value.inspect do + let(:params) {{ value: value }} + it { is_expected.to compile } + end + end + end + + describe 'rejects other values' do + [ + [], + {}, + 1, + true, + ].each do |value| + describe value.inspect do + let(:params) {{ value: value }} + it { is_expected.to compile.and_raise_error(/parameter 'value' expects a Stdlib::Compat::String = String/) } + end + end + end + end +end -- cgit v1.2.3 From cce67b42bb6d09d4e9773b64e28c07d8a93ed088 Mon Sep 17 00:00:00 2001 From: Dominic Cleal Date: Tue, 4 Oct 2016 09:36:20 +0100 Subject: Permit undef passed as `nil` to validate_string When validate_string is called via the Puppet 4 deprecation wrappers from deprecation_gen (introduced in 970852d), `undef` is passed as `nil` where it was previously passed as `''` from the Puppet 3-style function API. This change explicitly permits a `nil` value in validate_string, and adds a test case to `is_string` which also accepts the same. Fixes test failures in apt, concat etc: Error while evaluating a Function Call, nil is not a string. It looks to be a NilClass at apt/manifests/source.pp:23:3 [..] # ./spec/fixtures/modules/stdlib/lib/puppet/parser/functions/validate_string.rb:34:in `block (2 levels) in ' # ./spec/fixtures/modules/stdlib/lib/puppet/parser/functions/validate_string.rb:32:in `each' # ./spec/fixtures/modules/stdlib/lib/puppet/parser/functions/validate_string.rb:32:in `block in ' # puppet-4.7.0/lib/puppet/parser/functions.rb:174:in `block (2 levels) in newfunction' # puppet-4.7.0/lib/puppet/util/profiler/around_profiler.rb:58:in `profile' # puppet-4.7.0/lib/puppet/util/profiler.rb:51:in `profile' # puppet-4.7.0/lib/puppet/parser/functions.rb:167:in `block in newfunction' # ./spec/fixtures/modules/stdlib/lib/puppet_x/puppetlabs/stdlib/deprecation_gen.rb:13:in `block (2 levels) in deprecation_gen' --- spec/aliases/string_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'spec/aliases/string_spec.rb') diff --git a/spec/aliases/string_spec.rb b/spec/aliases/string_spec.rb index 8e01d55..853b5af 100644 --- a/spec/aliases/string_spec.rb +++ b/spec/aliases/string_spec.rb @@ -6,6 +6,7 @@ if Puppet.version.to_f >= 4.0 [ '', 'one', + nil, ].each do |value| describe value.inspect do let(:params) {{ value: value }} @@ -23,7 +24,7 @@ if Puppet.version.to_f >= 4.0 ].each do |value| describe value.inspect do let(:params) {{ value: value }} - it { is_expected.to compile.and_raise_error(/parameter 'value' expects a Stdlib::Compat::String = String/) } + it { is_expected.to compile.and_raise_error(/parameter 'value' expects a String/) } end end end -- cgit v1.2.3 From 4aa519e998f2f4ce567bcaae5880800884a44bf6 Mon Sep 17 00:00:00 2001 From: Helen Campbell Date: Thu, 6 Oct 2016 14:19:14 +0100 Subject: Corrects Puppet version for compat types tests --- spec/aliases/string_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/aliases/string_spec.rb') diff --git a/spec/aliases/string_spec.rb b/spec/aliases/string_spec.rb index 853b5af..8a93585 100644 --- a/spec/aliases/string_spec.rb +++ b/spec/aliases/string_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -if Puppet.version.to_f >= 4.0 +if Puppet.version.to_f >= 4.5 describe 'test::string', type: :class do describe 'accepts strings' do [ -- cgit v1.2.3