validate_cmd_spec.rb 2.0 KB

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