Skip to content

Commit 1b934ab

Browse files
committed
cleanups and missing testcase
1 parent fc3ca21 commit 1b934ab

2 files changed

Lines changed: 27 additions & 10 deletions

File tree

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,37 @@
11
require 'spec_helper'
22

33
if Puppet.version.to_f >= 4.0
4+
# validate_legacy requires a proper scope to run, so we have to trigger a true compilation here,
5+
# instead of being able to leverage the function test group.
46
describe 'test::validate_legacy', type: :class do
5-
7+
68
describe 'validate_legacy passes assertion of type but not previous validation' do
7-
let(:params) {{ type: "Optional[Integer]", prev_validation: "validate_re", value: 5, previous_args1: ["^\\d+$", ""] }}
9+
let(:params) {{ type: "Optional[Integer]", prev_validation: "validate_re", value: 5, previous_arg1: ["^\\d+$", ""] }}
810
it { Puppet.expects(:warn).with(includes('Accepting previously invalid value for target_type'))
911
is_expected.to compile }
1012
end
1113

1214
describe 'validate_legacy passes assertion of type and previous validation' do
13-
let(:params) {{ type: "Optional[String]", prev_validation: "validate_re", value: "5", previous_args1: ["."] }}
15+
let(:params) {{ type: "Optional[String]", prev_validation: "validate_re", value: "5", previous_arg1: ["."] }}
1416
it { is_expected.to compile }
1517
end
1618

1719
describe 'validate_legacy fails assertion of type and passes previous validation' do
18-
let(:params) {{ type: "Optional[Integer]", prev_validation: "validate_re", value: "5", previous_args1: ["."] }}
19-
it { Puppet.expects(:warn).with(includes('expected'))
20-
is_expected.to compile }
20+
let(:params) {{ type: "Optional[Integer]", prev_validation: "validate_re", value: "5", previous_arg1: ["."] }}
21+
it {
22+
Puppet.expects(:warn).with(includes('expected'))
23+
is_expected.to compile
24+
}
2125
end
2226

2327
describe 'validate_legacy fails assertion and fails previous validation' do
24-
let(:params) {{ type: "Optional[Integer]", prev_validation: "validate_re", value: "5", previous_args1: ["thisisnotright"] }}
28+
let(:params) {{ type: "Optional[Integer]", prev_validation: "validate_re", value: "5", previous_arg1: ["thisisnotright"] }}
2529
it { is_expected.to compile.and_raise_error(/Error while evaluating a Function Call, \w* expected an \w* value, got \w*/) }
2630
end
2731

32+
describe 'validate_legacy works with multi-argument validate_ functions' do
33+
let(:params) {{ type: "Integer", prev_validation: "validate_integer", value: 10, previous_arg1: 0, previous_arg2: 100 }}
34+
it { is_expected.to compile }
35+
end
2836
end
2937
end
Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
# Class to test stdlib validate_legacy function
22

3-
class test::validate_legacy( $type, $prev_validation, $value, $previous_args1
4-
) {
3+
class test::validate_legacy(
4+
$type,
5+
$prev_validation,
6+
$value,
7+
$previous_arg1,
8+
$previous_arg2 = undef,
9+
) {
510

6-
validate_legacy( $type, $prev_validation, $value, $previous_args1 )
11+
if $previous_arg2 == undef {
12+
validate_legacy( $type, $prev_validation, $value, $previous_arg1 )
13+
} else {
14+
validate_legacy( $type, $prev_validation, $value, $previous_arg1, $previous_arg2 )
15+
}
716
notice("Success")
817

918
}

0 commit comments

Comments
 (0)