Update puppetlabs/stdlib module
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / validate_cmd_spec.rb
1 require 'spec_helper'
2
3 describe 'validate_cmd', :unless => Puppet::Util::Platform.windows? do
4   let(:touch) { File.exist?('/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, %r{wrong number of arguments}i) }
9     it { is_expected.to run.with_params('').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
10     it { is_expected.to run.with_params('', '', '', 'extra').and_raise_error(Puppet::ParseError, %r{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, %r{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, %r{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, %r{custom error message must be a string})
22     }
23   end
24
25   context 'when validation fails' do
26     context 'with % placeholder' do
27       it {
28         is_expected.to run
29           .with_params('', "#{touch} % /no/such/file").and_raise_error(Puppet::ParseError, %r{Execution of '#{touch} \S+ \/no\/such\/file' returned 1:.*(cannot touch|o such file or)})
30       }
31       it { is_expected.to run.with_params('', "#{touch} % /no/such/file", 'custom error').and_raise_error(Puppet::ParseError, %r{custom error}) }
32     end
33     context 'without % placeholder' do
34       it {
35         is_expected.to run
36           .with_params('', "#{touch} /no/such/file").and_raise_error(Puppet::ParseError, %r{Execution of '#{touch} \/no\/such\/file \S+' returned 1:.*(cannot touch|o such file or)})
37       }
38       it { is_expected.to run.with_params('', "#{touch} /no/such/file", 'custom error').and_raise_error(Puppet::ParseError, %r{custom error}) }
39     end
40   end
41 end