validate_legacy_spec.rb 2.5 KB

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