1 | require 'spec_helper'
|
---|
2 |
|
---|
3 | if Puppet.version.to_f >= 4.0
|
---|
4 | describe 'validate_legacy' do
|
---|
5 | it { is_expected.not_to eq(nil) }
|
---|
6 | it { is_expected.to run.with_params.and_raise_error(ArgumentError) }
|
---|
7 |
|
---|
8 | describe 'when passing the type assertion and passing the previous validation' do
|
---|
9 | before do
|
---|
10 | scope.expects(:function_validate_foo).with([5]).once
|
---|
11 | Puppet.expects(:notice).never
|
---|
12 | end
|
---|
13 | it 'passes without notice' do
|
---|
14 | is_expected.to run.with_params('Integer', 'validate_foo', 5)
|
---|
15 | end
|
---|
16 | end
|
---|
17 |
|
---|
18 | describe 'when passing the type assertion and failing the previous validation' do
|
---|
19 | before do
|
---|
20 | scope.expects(:function_validate_foo).with([5]).raises(Puppet::ParseError, 'foo').once
|
---|
21 | Puppet.expects(:notice).with(includes('Accepting previously invalid value for target type'))
|
---|
22 | end
|
---|
23 | it 'passes with a notice about newly accepted value' do
|
---|
24 | is_expected.to run.with_params('Integer', 'validate_foo', 5)
|
---|
25 | end
|
---|
26 | end
|
---|
27 |
|
---|
28 | describe 'when failing the type assertion and passing the previous validation' do
|
---|
29 | before do
|
---|
30 | scope.expects(:function_validate_foo).with(['5']).once
|
---|
31 | subject.func.expects(:call_function).with('deprecation', 'validate_legacy', includes('expected an Integer value')).once
|
---|
32 | end
|
---|
33 | it 'passes with a deprecation message' do
|
---|
34 | is_expected.to run.with_params('Integer', 'validate_foo', '5')
|
---|
35 | end
|
---|
36 | end
|
---|
37 |
|
---|
38 | describe 'when failing the type assertion and failing the previous validation' do
|
---|
39 | before do
|
---|
40 | scope.expects(:function_validate_foo).with(['5']).raises(Puppet::ParseError, 'foo').once
|
---|
41 | subject.func.expects(:call_function).with('fail', includes('expected an Integer value')).once
|
---|
42 | end
|
---|
43 | it 'fails with a helpful message' do
|
---|
44 | is_expected.to run.with_params('Integer', 'validate_foo', '5')
|
---|
45 | end
|
---|
46 | end
|
---|
47 |
|
---|
48 | describe 'when passing in undef' do
|
---|
49 | before do
|
---|
50 | scope.expects(:function_validate_foo).with([:undef]).once
|
---|
51 | Puppet.expects(:notice).never
|
---|
52 | end
|
---|
53 | it 'works' do
|
---|
54 | is_expected.to run.with_params('Optional[Integer]', 'validate_foo', :undef)
|
---|
55 | end
|
---|
56 | end
|
---|
57 |
|
---|
58 | describe 'when passing in multiple arguments' do
|
---|
59 | before do
|
---|
60 | scope.expects(:function_validate_foo).with([:undef, 1, 'foo']).once
|
---|
61 | Puppet.expects(:notice).never
|
---|
62 | end
|
---|
63 | it 'passes with a deprecation message' do
|
---|
64 | is_expected.to run.with_params('Optional[Integer]', 'validate_foo', :undef, 1, 'foo')
|
---|
65 | end
|
---|
66 | end
|
---|
67 | end
|
---|
68 | end
|
---|