fragments_are_always_replaced_spec.rb 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. it { should_not contain 'caller has replace unset run 1' }
  36. it { should contain 'caller has replace unset run 2' }
  37. end
  38. end # should create fragment files
  39. context 'should replace its own fragment files when caller has File { replace=>true } set' do
  40. before(:all) do
  41. pp = <<-EOS
  42. file { '#{basedir}':
  43. ensure => directory,
  44. }
  45. EOS
  46. apply_manifest(pp)
  47. end
  48. pp1 = <<-EOS
  49. File { replace=>true }
  50. concat { '#{basedir}/foo': }
  51. concat::fragment { '1':
  52. target => '#{basedir}/foo',
  53. content => 'caller has replace true set run 1',
  54. }
  55. EOS
  56. pp2 = <<-EOS
  57. File { replace=>true }
  58. concat { '#{basedir}/foo': }
  59. concat::fragment { '1':
  60. target => '#{basedir}/foo',
  61. content => 'caller has replace true set run 2',
  62. }
  63. EOS
  64. it 'applies the manifest twice with no stderr' do
  65. apply_manifest(pp1, :catch_failures => true)
  66. apply_manifest(pp1, :catch_changes => true)
  67. apply_manifest(pp2, :catch_failures => true)
  68. apply_manifest(pp2, :catch_changes => true)
  69. end
  70. describe file("#{basedir}/foo") do
  71. it { should be_file }
  72. it { should_not contain 'caller has replace true set run 1' }
  73. it { should contain 'caller has replace true set run 2' }
  74. end
  75. end # should replace its own fragment files when caller has File(replace=>true) set
  76. context 'should replace its own fragment files even when caller has File { replace=>false } set' do
  77. before(:all) do
  78. pp = <<-EOS
  79. file { '#{basedir}':
  80. ensure => directory,
  81. }
  82. EOS
  83. apply_manifest(pp)
  84. end
  85. pp1 = <<-EOS
  86. File { replace=>false }
  87. concat { '#{basedir}/foo': }
  88. concat::fragment { '1':
  89. target => '#{basedir}/foo',
  90. content => 'caller has replace false set run 1',
  91. }
  92. EOS
  93. pp2 = <<-EOS
  94. File { replace=>false }
  95. concat { '#{basedir}/foo': }
  96. concat::fragment { '1':
  97. target => '#{basedir}/foo',
  98. content => 'caller has replace false set run 2',
  99. }
  100. EOS
  101. it 'applies the manifest twice with no stderr' do
  102. apply_manifest(pp1, :catch_failures => true)
  103. apply_manifest(pp1, :catch_changes => true)
  104. apply_manifest(pp2, :catch_failures => true)
  105. apply_manifest(pp2, :catch_changes => true)
  106. end
  107. describe file("#{basedir}/foo") do
  108. it { should be_file }
  109. it { should_not contain 'caller has replace false set run 1' }
  110. it { should contain 'caller has replace false set run 2' }
  111. end
  112. end # should replace its own fragment files even when caller has File(replace=>false) set
  113. end