concat_spec.rb 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. require 'spec_helper_acceptance'
  2. case fact('osfamily')
  3. when 'AIX'
  4. username = 'root'
  5. groupname = 'system'
  6. scriptname = 'concatfragments.rb'
  7. vardir = default['puppetvardir']
  8. when 'Darwin'
  9. username = 'root'
  10. groupname = 'wheel'
  11. scriptname = 'concatfragments.rb'
  12. vardir = default['puppetvardir']
  13. when 'windows'
  14. username = 'Administrator'
  15. groupname = 'Administrators'
  16. scriptname = 'concatfragments.rb'
  17. result = on default, "echo #{default['puppetvardir']}"
  18. vardir = result.raw_output.chomp
  19. when 'Solaris'
  20. username = 'root'
  21. groupname = 'root'
  22. scriptname = 'concatfragments.rb'
  23. vardir = default['puppetvardir']
  24. else
  25. username = 'root'
  26. groupname = 'root'
  27. scriptname = 'concatfragments.rb'
  28. vardir = default['puppetvardir']
  29. end
  30. describe 'basic concat test' do
  31. basedir = default.tmpdir('concat')
  32. safe_basedir = basedir.gsub(/[\/:]/, '_')
  33. shared_examples 'successfully_applied' do |pp|
  34. it 'applies the manifest twice with no stderr' do
  35. apply_manifest(pp, :catch_failures => true)
  36. apply_manifest(pp, :catch_changes => true)
  37. end
  38. describe file("#{vardir}/concat") do
  39. it { should be_directory }
  40. it { should be_owned_by username }
  41. it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) {
  42. should be_mode 755
  43. }
  44. end
  45. describe file("#{vardir}/concat/bin") do
  46. it { should be_directory }
  47. it { should be_owned_by username }
  48. it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) {
  49. should be_mode 755
  50. }
  51. end
  52. describe file("#{vardir}/concat/bin/#{scriptname}") do
  53. it { should be_file }
  54. it { should be_owned_by username }
  55. it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) {
  56. should be_mode 755
  57. }
  58. end
  59. describe file("#{vardir}/concat/#{safe_basedir}_file") do
  60. it { should be_directory }
  61. it { should be_owned_by username }
  62. it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) {
  63. should be_mode 750
  64. }
  65. end
  66. describe file("#{vardir}/concat/#{safe_basedir}_file/fragments") do
  67. it { should be_directory }
  68. it { should be_owned_by username }
  69. it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) {
  70. should be_mode 750
  71. }
  72. end
  73. describe file("#{vardir}/concat/#{safe_basedir}_file/fragments.concat") do
  74. it { should be_file }
  75. it { should be_owned_by username }
  76. it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) {
  77. should be_mode 640
  78. }
  79. end
  80. describe file("#{vardir}/concat/#{safe_basedir}_file/fragments.concat.out") do
  81. it { should be_file }
  82. it { should be_owned_by username }
  83. it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) {
  84. should be_mode 640
  85. }
  86. end
  87. end
  88. context 'owner/group root' do
  89. before(:all) do
  90. pp = <<-EOS
  91. file { '#{basedir}':
  92. ensure => directory,
  93. }
  94. EOS
  95. apply_manifest(pp)
  96. end
  97. pp = <<-EOS
  98. concat { '#{basedir}/file':
  99. owner => '#{username}',
  100. group => '#{groupname}',
  101. mode => '0644',
  102. }
  103. concat::fragment { '1':
  104. target => '#{basedir}/file',
  105. content => '1',
  106. order => '01',
  107. }
  108. concat::fragment { '2':
  109. target => '#{basedir}/file',
  110. content => '2',
  111. order => '02',
  112. }
  113. EOS
  114. it_behaves_like 'successfully_applied', pp
  115. describe file("#{basedir}/file") do
  116. it { should be_file }
  117. it { should be_owned_by username }
  118. it("should be group", :unless => (fact('osfamily') == 'windows')) { should be_grouped_into groupname }
  119. it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) {
  120. should be_mode 644
  121. }
  122. its(:content) {
  123. should match '1'
  124. should match '2'
  125. }
  126. end
  127. describe file("#{vardir}/concat/#{safe_basedir}_file/fragments/01_1") do
  128. it { should be_file }
  129. it { should be_owned_by username }
  130. it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) {
  131. should be_mode 640
  132. }
  133. end
  134. describe file("#{vardir}/concat/#{safe_basedir}_file/fragments/02_2") do
  135. it { should be_file }
  136. it { should be_owned_by username }
  137. it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) {
  138. should be_mode 640
  139. }
  140. end
  141. end
  142. context 'ensure' do
  143. context 'works when set to present with path set' do
  144. before(:all) do
  145. pp = <<-EOS
  146. file { '#{basedir}':
  147. ensure => directory,
  148. }
  149. EOS
  150. apply_manifest(pp)
  151. end
  152. pp="
  153. concat { 'file':
  154. ensure => present,
  155. path => '#{basedir}/file',
  156. mode => '0644',
  157. }
  158. concat::fragment { '1':
  159. target => 'file',
  160. content => '1',
  161. order => '01',
  162. }
  163. "
  164. it_behaves_like 'successfully_applied', pp
  165. describe file("#{basedir}/file") do
  166. it { should be_file }
  167. it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) {
  168. should be_mode 644
  169. }
  170. its(:content) { should match '1' }
  171. end
  172. end
  173. context 'works when set to absent with path set' do
  174. before(:all) do
  175. pp = <<-EOS
  176. file { '#{basedir}':
  177. ensure => directory,
  178. }
  179. EOS
  180. apply_manifest(pp)
  181. end
  182. pp="
  183. concat { 'file':
  184. ensure => absent,
  185. path => '#{basedir}/file',
  186. mode => '0644',
  187. }
  188. concat::fragment { '1':
  189. target => 'file',
  190. content => '1',
  191. order => '01',
  192. }
  193. "
  194. it 'applies the manifest twice with no stderr' do
  195. apply_manifest(pp, :catch_failures => true)
  196. apply_manifest(pp, :catch_changes => true)
  197. end
  198. describe file("#{basedir}/file") do
  199. it { should_not be_file }
  200. end
  201. end
  202. end
  203. end