backup_spec.rb 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. require 'spec_helper_acceptance'
  2. describe 'concat backup parameter' do
  3. basedir = default.tmpdir('concat')
  4. context '=> puppet' do
  5. before(:all) do
  6. pp = <<-EOS
  7. file { '#{basedir}':
  8. ensure => directory,
  9. }
  10. file { '#{basedir}/file':
  11. content => "old contents\n",
  12. }
  13. EOS
  14. apply_manifest(pp)
  15. end
  16. pp = <<-EOS
  17. concat { '#{basedir}/file':
  18. backup => 'puppet',
  19. }
  20. concat::fragment { 'new file':
  21. target => '#{basedir}/file',
  22. content => 'new contents',
  23. }
  24. EOS
  25. it 'applies the manifest twice with "Filebucketed" stdout and no stderr' do
  26. apply_manifest(pp, :catch_failures => true) do |r|
  27. expect(r.stdout).to match(/Filebucketed #{basedir}\/file to puppet with sum 0140c31db86293a1a1e080ce9b91305f/) # sum is for file contents of 'old contents'
  28. end
  29. apply_manifest(pp, :catch_changes => true)
  30. end
  31. describe file("#{basedir}/file") do
  32. it { should be_file }
  33. it { should contain 'new contents' }
  34. end
  35. end
  36. context '=> .backup' do
  37. before(:all) do
  38. pp = <<-EOS
  39. file { '#{basedir}':
  40. ensure => directory,
  41. }
  42. file { '#{basedir}/file':
  43. content => "old contents\n",
  44. }
  45. EOS
  46. apply_manifest(pp)
  47. end
  48. pp = <<-EOS
  49. concat { '#{basedir}/file':
  50. backup => '.backup',
  51. }
  52. concat::fragment { 'new file':
  53. target => '#{basedir}/file',
  54. content => 'new contents',
  55. }
  56. EOS
  57. # XXX Puppet doesn't mention anything about filebucketing with a given
  58. # extension like .backup
  59. it 'applies the manifest twice no stderr' do
  60. apply_manifest(pp, :catch_failures => true)
  61. apply_manifest(pp, :catch_changes => true)
  62. end
  63. describe file("#{basedir}/file") do
  64. it { should be_file }
  65. it { should contain 'new contents' }
  66. end
  67. describe file("#{basedir}/file.backup") do
  68. it { should be_file }
  69. it { should contain 'old contents' }
  70. end
  71. end
  72. # XXX The backup parameter uses validate_string() and thus can't be the
  73. # boolean false value, but the string 'false' has the same effect in Puppet 3
  74. context "=> 'false'" do
  75. before(:all) do
  76. pp = <<-EOS
  77. file { '#{basedir}':
  78. ensure => directory,
  79. }
  80. file { '#{basedir}/file':
  81. content => "old contents\n",
  82. }
  83. EOS
  84. apply_manifest(pp)
  85. end
  86. pp = <<-EOS
  87. concat { '#{basedir}/file':
  88. backup => '.backup',
  89. }
  90. concat::fragment { 'new file':
  91. target => '#{basedir}/file',
  92. content => 'new contents',
  93. }
  94. EOS
  95. it 'applies the manifest twice with no "Filebucketed" stdout and no stderr' do
  96. apply_manifest(pp, :catch_failures => true) do |r|
  97. expect(r.stdout).to_not match(/Filebucketed/)
  98. end
  99. apply_manifest(pp, :catch_changes => true)
  100. end
  101. describe file("#{basedir}/file") do
  102. it { should be_file }
  103. it { should contain 'new contents' }
  104. end
  105. end
  106. end