concat_spec.rb 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. require 'spec_helper_acceptance'
  2. case fact('osfamily')
  3. when 'AIX'
  4. username = 'root'
  5. groupname = 'system'
  6. scriptname = 'concatfragments.sh'
  7. vardir = default['puppetvardir']
  8. when 'Darwin'
  9. username = 'root'
  10. groupname = 'wheel'
  11. scriptname = 'concatfragments.sh'
  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.sh'
  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. it { should contain '1' }
  123. it { should contain '2' }
  124. end
  125. describe file("#{vardir}/concat/#{safe_basedir}_file/fragments/01_1") do
  126. it { should be_file }
  127. it { should be_owned_by username }
  128. it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) {
  129. should be_mode 640
  130. }
  131. end
  132. describe file("#{vardir}/concat/#{safe_basedir}_file/fragments/02_2") do
  133. it { should be_file }
  134. it { should be_owned_by username }
  135. it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) {
  136. should be_mode 640
  137. }
  138. end
  139. end
  140. context 'ensure' do
  141. context 'works when set to present with path set' do
  142. before(:all) do
  143. pp = <<-EOS
  144. file { '#{basedir}':
  145. ensure => directory,
  146. }
  147. EOS
  148. apply_manifest(pp)
  149. end
  150. pp="
  151. concat { 'file':
  152. ensure => present,
  153. path => '#{basedir}/file',
  154. mode => '0644',
  155. }
  156. concat::fragment { '1':
  157. target => 'file',
  158. content => '1',
  159. order => '01',
  160. }
  161. "
  162. it_behaves_like 'successfully_applied', pp
  163. describe file("#{basedir}/file") do
  164. it { should be_file }
  165. it("should be mode", :unless => (fact('osfamily') == 'AIX' or fact('osfamily') == 'windows')) {
  166. should be_mode 644
  167. }
  168. it { should contain '1' }
  169. end
  170. end
  171. context 'works when set to absent with path set' do
  172. before(:all) do
  173. pp = <<-EOS
  174. file { '#{basedir}':
  175. ensure => directory,
  176. }
  177. EOS
  178. apply_manifest(pp)
  179. end
  180. pp="
  181. concat { 'file':
  182. ensure => absent,
  183. path => '#{basedir}/file',
  184. mode => '0644',
  185. }
  186. concat::fragment { '1':
  187. target => 'file',
  188. content => '1',
  189. order => '01',
  190. }
  191. "
  192. it 'applies the manifest twice with no stderr' do
  193. apply_manifest(pp, :catch_failures => true)
  194. apply_manifest(pp, :catch_changes => true)
  195. end
  196. describe file("#{basedir}/file") do
  197. it { should_not be_file }
  198. end
  199. end
  200. end
  201. end