fragment_source_spec.rb 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. require 'spec_helper_acceptance'
  2. case fact('osfamily')
  3. when 'AIX'
  4. username = 'root'
  5. groupname = 'system'
  6. when 'Darwin'
  7. username = 'root'
  8. groupname = 'wheel'
  9. when 'windows'
  10. username = 'Administrator'
  11. groupname = 'Administrators'
  12. else
  13. username = 'root'
  14. groupname = 'root'
  15. end
  16. describe 'concat::fragment source' do
  17. basedir = default.tmpdir('concat')
  18. context 'should read file fragments from local system' do
  19. pp = <<-EOS
  20. file { '#{basedir}/file1':
  21. content => "file1 contents\n"
  22. }
  23. file { '#{basedir}/file2':
  24. content => "file2 contents\n"
  25. }
  26. concat { '#{basedir}/foo': }
  27. concat::fragment { '1':
  28. target => '#{basedir}/foo',
  29. source => '#{basedir}/file1',
  30. require => File['#{basedir}/file1'],
  31. }
  32. concat::fragment { '2':
  33. target => '#{basedir}/foo',
  34. content => 'string1 contents',
  35. }
  36. concat::fragment { '3':
  37. target => '#{basedir}/foo',
  38. source => '#{basedir}/file2',
  39. require => File['#{basedir}/file2'],
  40. }
  41. EOS
  42. it 'applies the manifest twice with no stderr' do
  43. apply_manifest(pp, :catch_failures => true)
  44. apply_manifest(pp, :catch_changes => true)
  45. end
  46. describe file("#{basedir}/foo") do
  47. it { should be_file }
  48. it { should contain 'file1 contents' }
  49. it { should contain 'string1 contents' }
  50. it { should contain 'file2 contents' }
  51. end
  52. end # should read file fragments from local system
  53. context 'should create files containing first match only.' do
  54. pp = <<-EOS
  55. file { '#{basedir}/file1':
  56. content => "file1 contents\n"
  57. }
  58. file { '#{basedir}/file2':
  59. content => "file2 contents\n"
  60. }
  61. concat { '#{basedir}/result_file1':
  62. owner => '#{username}',
  63. group => '#{groupname}',
  64. mode => '0644',
  65. }
  66. concat { '#{basedir}/result_file2':
  67. owner => '#{username}',
  68. group => '#{groupname}',
  69. mode => '0644',
  70. }
  71. concat { '#{basedir}/result_file3':
  72. owner => '#{username}',
  73. group => '#{groupname}',
  74. mode => '0644',
  75. }
  76. concat::fragment { '1':
  77. target => '#{basedir}/result_file1',
  78. source => [ '#{basedir}/file1', '#{basedir}/file2' ],
  79. require => [ File['#{basedir}/file1'], File['#{basedir}/file2'] ],
  80. order => '01',
  81. }
  82. concat::fragment { '2':
  83. target => '#{basedir}/result_file2',
  84. source => [ '#{basedir}/file2', '#{basedir}/file1' ],
  85. require => [ File['#{basedir}/file1'], File['#{basedir}/file2'] ],
  86. order => '01',
  87. }
  88. concat::fragment { '3':
  89. target => '#{basedir}/result_file3',
  90. source => [ '#{basedir}/file1', '#{basedir}/file2' ],
  91. require => [ File['#{basedir}/file1'], File['#{basedir}/file2'] ],
  92. order => '01',
  93. }
  94. EOS
  95. it 'applies the manifest twice with no stderr' do
  96. apply_manifest(pp, :catch_failures => true)
  97. apply_manifest(pp, :catch_changes => true)
  98. end
  99. describe file("#{basedir}/result_file1") do
  100. it { should be_file }
  101. it { should contain 'file1 contents' }
  102. it { should_not contain 'file2 contents' }
  103. end
  104. describe file("#{basedir}/result_file2") do
  105. it { should be_file }
  106. it { should contain 'file2 contents' }
  107. it { should_not contain 'file1 contents' }
  108. end
  109. describe file("#{basedir}/result_file3") do
  110. it { should be_file }
  111. it { should contain 'file1 contents' }
  112. it { should_not contain 'file2 contents' }
  113. end
  114. end
  115. context 'should fail if no match on source.' do
  116. pp = <<-EOS
  117. concat { '#{basedir}/fail_no_source':
  118. owner => '#{username}',
  119. group => '#{groupname}',
  120. mode => '0644',
  121. }
  122. concat::fragment { '1':
  123. target => '#{basedir}/fail_no_source',
  124. source => [ '#{basedir}/nofilehere', '#{basedir}/nothereeither' ],
  125. order => '01',
  126. }
  127. EOS
  128. it 'applies the manifest with resource failures' do
  129. apply_manifest(pp, :expect_failures => true)
  130. end
  131. describe file("#{basedir}/fail_no_source") do
  132. #FIXME: Serverspec::Type::File doesn't support exists? for some reason. so... hack.
  133. it { should_not be_file }
  134. it { should_not be_directory }
  135. end
  136. end
  137. end