order_spec.rb 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. require 'spec_helper_acceptance'
  2. describe 'concat order' do
  3. basedir = default.tmpdir('concat')
  4. context '=> ' do
  5. shared_examples 'sortby' do |order_by, match_output|
  6. pp = <<-EOS
  7. concat { '#{basedir}/foo':
  8. order => '#{order_by}'
  9. }
  10. concat::fragment { '1':
  11. target => '#{basedir}/foo',
  12. content => 'string1',
  13. order => '1',
  14. }
  15. concat::fragment { '2':
  16. target => '#{basedir}/foo',
  17. content => 'string2',
  18. order => '2',
  19. }
  20. concat::fragment { '10':
  21. target => '#{basedir}/foo',
  22. content => 'string10',
  23. }
  24. EOS
  25. it 'applies the manifest twice with no stderr' do
  26. apply_manifest(pp, :catch_failures => true)
  27. apply_manifest(pp, :catch_changes => true)
  28. end
  29. describe file("#{basedir}/foo") do
  30. it { should be_file }
  31. its(:content) { should match match_output }
  32. end
  33. end
  34. describe 'alpha' do
  35. it_behaves_like 'sortby', 'alpha', /string10string1string2/
  36. end
  37. describe 'numeric' do
  38. it_behaves_like 'sortby', 'numeric', /string1string2string10/
  39. end
  40. end
  41. end # concat order
  42. describe 'concat::fragment order' do
  43. basedir = default.tmpdir('concat')
  44. context '=> reverse order' do
  45. shared_examples 'order_by' do |order_by, match_output|
  46. pp = <<-EOS
  47. concat { '#{basedir}/foo':
  48. order => '#{order_by}'
  49. }
  50. concat::fragment { '1':
  51. target => '#{basedir}/foo',
  52. content => 'string1',
  53. order => '15',
  54. }
  55. concat::fragment { '2':
  56. target => '#{basedir}/foo',
  57. content => 'string2',
  58. # default order 10
  59. }
  60. concat::fragment { '3':
  61. target => '#{basedir}/foo',
  62. content => 'string3',
  63. order => '1',
  64. }
  65. EOS
  66. it 'applies the manifest twice with no stderr' do
  67. apply_manifest(pp, :catch_failures => true)
  68. apply_manifest(pp, :catch_changes => true)
  69. end
  70. describe file("#{basedir}/foo") do
  71. it { should be_file }
  72. its(:content) { should match match_output }
  73. end
  74. end
  75. describe 'alpha' do
  76. it_should_behave_like 'order_by', 'alpha', /string2string1string3/
  77. end
  78. describe 'numeric' do
  79. it_should_behave_like 'order_by', 'numeric', /string3string2string1/
  80. end
  81. end
  82. context '=> normal order' do
  83. pp = <<-EOS
  84. concat { '#{basedir}/foo': }
  85. concat::fragment { '1':
  86. target => '#{basedir}/foo',
  87. content => 'string1',
  88. order => '01',
  89. }
  90. concat::fragment { '2':
  91. target => '#{basedir}/foo',
  92. content => 'string2',
  93. order => '02'
  94. }
  95. concat::fragment { '3':
  96. target => '#{basedir}/foo',
  97. content => 'string3',
  98. order => '03',
  99. }
  100. EOS
  101. it 'applies the manifest twice with no stderr' do
  102. apply_manifest(pp, :catch_failures => true)
  103. apply_manifest(pp, :catch_changes => true)
  104. end
  105. describe file("#{basedir}/foo") do
  106. it { should be_file }
  107. its(:content) { should match /string1string2string3/ }
  108. end
  109. end
  110. end # concat::fragment order