1 | require 'spec_helper'
|
---|
2 |
|
---|
3 | describe 'validate_cmd' do
|
---|
4 | let(:touch) { File.exists?('/usr/bin/touch') ? '/usr/bin/touch' : '/bin/touch' }
|
---|
5 |
|
---|
6 | describe 'signature validation' do
|
---|
7 | it { is_expected.not_to eq(nil) }
|
---|
8 | it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
|
---|
9 | it { is_expected.to run.with_params('').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
|
---|
10 | it { is_expected.to run.with_params('', '', '', 'extra').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
|
---|
11 | it {
|
---|
12 | pending('should implement stricter type checking')
|
---|
13 | is_expected.to run.with_params([], '', '').and_raise_error(Puppet::ParseError, /content must be a string/)
|
---|
14 | }
|
---|
15 | it {
|
---|
16 | pending('should implement stricter type checking')
|
---|
17 | is_expected.to run.with_params('', [], '').and_raise_error(Puppet::ParseError, /checkscript must be a string/)
|
---|
18 | }
|
---|
19 | it {
|
---|
20 | pending('should implement stricter type checking')
|
---|
21 | is_expected.to run.with_params('', '', []).and_raise_error(Puppet::ParseError, /custom error message must be a string/)
|
---|
22 | }
|
---|
23 | end
|
---|
24 |
|
---|
25 | context 'when validation fails' do
|
---|
26 | context 'with % placeholder' do
|
---|
27 | it { is_expected.to run.with_params('', "#{touch} % /no/such/file").and_raise_error(Puppet::ParseError, /Execution of '#{touch} \S+ \/no\/such\/file' returned 1:.*(cannot touch|o such file or)/) }
|
---|
28 | it { is_expected.to run.with_params('', "#{touch} % /no/such/file", 'custom error').and_raise_error(Puppet::ParseError, /custom error/) }
|
---|
29 | end
|
---|
30 | context 'without % placeholder' do
|
---|
31 | it { is_expected.to run.with_params('', "#{touch} /no/such/file").and_raise_error(Puppet::ParseError, /Execution of '#{touch} \/no\/such\/file \S+' returned 1:.*(cannot touch|o such file or)/) }
|
---|
32 | it { is_expected.to run.with_params('', "#{touch} /no/such/file", 'custom error').and_raise_error(Puppet::ParseError, /custom error/) }
|
---|
33 | end
|
---|
34 | end
|
---|
35 | end
|
---|