fragments_are_always_replaced_spec.rb 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. require 'spec_helper_acceptance'
  2. describe 'concat::fragment replace' do
  3. basedir = default.tmpdir('concat')
  4. context 'should create fragment files' do
  5. before(:all) do
  6. pp = <<-EOS
  7. file { '#{basedir}':
  8. ensure => directory,
  9. }
  10. EOS
  11. apply_manifest(pp)
  12. end
  13. pp1 = <<-EOS
  14. concat { '#{basedir}/foo': }
  15. concat::fragment { '1':
  16. target => '#{basedir}/foo',
  17. content => 'caller has replace unset run 1',
  18. }
  19. EOS
  20. pp2 = <<-EOS
  21. concat { '#{basedir}/foo': }
  22. concat::fragment { '1':
  23. target => '#{basedir}/foo',
  24. content => 'caller has replace unset run 2',
  25. }
  26. EOS
  27. it 'applies the manifest twice with no stderr' do
  28. apply_manifest(pp1, :catch_failures => true)
  29. apply_manifest(pp1, :catch_changes => true)
  30. apply_manifest(pp2, :catch_failures => true)
  31. apply_manifest(pp2, :catch_changes => true)
  32. end
  33. describe file("#{basedir}/foo") do
  34. it { should be_file }
  35. its(:content) {
  36. should_not match 'caller has replace unset run 1'
  37. should match 'caller has replace unset run 2'
  38. }
  39. end
  40. end # should create fragment files
  41. context 'should replace its own fragment files when caller has File { replace=>true } set' do
  42. before(:all) do
  43. pp = <<-EOS
  44. file { '#{basedir}':
  45. ensure => directory,
  46. }
  47. EOS
  48. apply_manifest(pp)
  49. end
  50. pp1 = <<-EOS
  51. File { replace=>true }
  52. concat { '#{basedir}/foo': }
  53. concat::fragment { '1':
  54. target => '#{basedir}/foo',
  55. content => 'caller has replace true set run 1',
  56. }
  57. EOS
  58. pp2 = <<-EOS
  59. File { replace=>true }
  60. concat { '#{basedir}/foo': }
  61. concat::fragment { '1':
  62. target => '#{basedir}/foo',
  63. content => 'caller has replace true set run 2',
  64. }
  65. EOS
  66. it 'applies the manifest twice with no stderr' do
  67. apply_manifest(pp1, :catch_failures => true)
  68. apply_manifest(pp1, :catch_changes => true)
  69. apply_manifest(pp2, :catch_failures => true)
  70. apply_manifest(pp2, :catch_changes => true)
  71. end
  72. describe file("#{basedir}/foo") do
  73. it { should be_file }
  74. its(:content) {
  75. should_not match 'caller has replace true set run 1'
  76. should match 'caller has replace true set run 2'
  77. }
  78. end
  79. end # should replace its own fragment files when caller has File(replace=>true) set
  80. context 'should replace its own fragment files even when caller has File { replace=>false } set' do
  81. before(:all) do
  82. pp = <<-EOS
  83. file { '#{basedir}':
  84. ensure => directory,
  85. }
  86. EOS
  87. apply_manifest(pp)
  88. end
  89. pp1 = <<-EOS
  90. File { replace=>false }
  91. concat { '#{basedir}/foo': }
  92. concat::fragment { '1':
  93. target => '#{basedir}/foo',
  94. content => 'caller has replace false set run 1',
  95. }
  96. EOS
  97. pp2 = <<-EOS
  98. File { replace=>false }
  99. concat { '#{basedir}/foo': }
  100. concat::fragment { '1':
  101. target => '#{basedir}/foo',
  102. content => 'caller has replace false set run 2',
  103. }
  104. EOS
  105. it 'applies the manifest twice with no stderr' do
  106. apply_manifest(pp1, :catch_failures => true)
  107. apply_manifest(pp1, :catch_changes => true)
  108. apply_manifest(pp2, :catch_failures => true)
  109. apply_manifest(pp2, :catch_changes => true)
  110. end
  111. describe file("#{basedir}/foo") do
  112. it { should be_file }
  113. its(:content) {
  114. should_not match 'caller has replace false set run 1'
  115. should match 'caller has replace false set run 2'
  116. }
  117. end
  118. end # should replace its own fragment files even when caller has File(replace=>false) set
  119. end