deprecation_spec.rb 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. require 'spec_helper_acceptance'
  2. describe 'deprecation function' do
  3. test_file = if fact('operatingsystem') == 'windows'
  4. 'C:/deprecation'
  5. else
  6. '/tmp/deprecation'
  7. end
  8. # It seems that Windows needs everything to be on one line when using puppet apply -e, otherwise the manifests would be in an easier format
  9. add_file_manifest = "\"deprecation('key', 'message') file { '#{test_file}': ensure => present, content => 'test', }\""
  10. remove_file_manifest = "file { '#{test_file}': ensure => absent }"
  11. before :all do
  12. apply_manifest(remove_file_manifest)
  13. end
  14. context 'with --strict=error', :if => return_puppet_version =~ %r{^4} do
  15. let(:result) { on(default, puppet('apply', '--strict=error', '-e', add_file_manifest), :acceptable_exit_codes => (0...256)) }
  16. after :all do
  17. apply_manifest(remove_file_manifest)
  18. end
  19. it 'returns an error' do
  20. expect(result.exit_code).to eq(1)
  21. end
  22. it 'shows the error message' do
  23. expect(result.stderr).to match(%r{deprecation. key. message})
  24. end
  25. describe file(test_file.to_s) do
  26. it { is_expected.not_to be_file }
  27. end
  28. end
  29. context 'with --strict=warning', :if => return_puppet_version =~ %r{^4} do
  30. let(:result) { on(default, puppet('apply', '--strict=warning', '-e', add_file_manifest), :acceptable_exit_codes => (0...256)) }
  31. after :all do
  32. apply_manifest(remove_file_manifest)
  33. end
  34. it 'does not return an error' do
  35. expect(result.exit_code).to eq(0)
  36. end
  37. it 'shows the error message' do
  38. expect(result.stderr).to match(%r{Warning: message})
  39. end
  40. describe file(test_file.to_s) do
  41. it { is_expected.to be_file }
  42. end
  43. end
  44. context 'with --strict=off', :if => return_puppet_version =~ %r{^4} do
  45. let(:result) { on(default, puppet('apply', '--strict=off', '-e', add_file_manifest), :acceptable_exit_codes => (0...256)) }
  46. after :all do
  47. apply_manifest(remove_file_manifest)
  48. end
  49. it 'does not return an error' do
  50. expect(result.exit_code).to eq(0)
  51. end
  52. it 'does not show the error message' do
  53. expect(result.stderr).not_to match(%r{Warning: message})
  54. end
  55. describe file(test_file.to_s) do
  56. it { is_expected.to be_file }
  57. end
  58. end
  59. context 'puppet 3 test', :if => return_puppet_version =~ %r{^3} do
  60. let(:result) { on(default, puppet('apply', '--parser=future', '-e', add_file_manifest), :acceptable_exit_codes => (0...256)) }
  61. after :all do
  62. apply_manifest(remove_file_manifest)
  63. end
  64. it 'returns a deprecation error' do
  65. expect(result.stderr).to match(%r{Warning: message})
  66. end
  67. it 'passes without error' do
  68. expect(result.exit_code).to eq(0)
  69. end
  70. end
  71. end