diff options
author | Helen Campbell <helen@puppetlabs.com> | 2016-08-10 14:17:16 +0100 |
---|---|---|
committer | Helen Campbell <helen@puppetlabs.com> | 2016-08-11 18:59:15 +0100 |
commit | adf922c28441bc95f5cbac1f0951256c080b3298 (patch) | |
tree | 709bcf434658a291ce9a87e3bc4639992141725b /spec/classes | |
parent | 999c267a3871c7d59513869c94c43c3477f1c6f1 (diff) |
(WIP) Addition of validate legacy function
Diffstat (limited to 'spec/classes')
-rw-r--r-- | spec/classes/validate_legacy_spec.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/spec/classes/validate_legacy_spec.rb b/spec/classes/validate_legacy_spec.rb new file mode 100644 index 0000000..ded6890 --- /dev/null +++ b/spec/classes/validate_legacy_spec.rb @@ -0,0 +1,39 @@ +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 |