deprecation_warnings_spec.rb 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. require 'spec_helper_acceptance'
  2. describe 'deprecation warnings' do
  3. basedir = default.tmpdir('concat')
  4. shared_examples 'has_warning'do |pp, w|
  5. it 'applies the manifest twice with a stderr regex' do
  6. expect(apply_manifest(pp, :catch_failures => true).stderr).to match(/#{Regexp.escape(w)}/m)
  7. expect(apply_manifest(pp, :catch_changes => true).stderr).to match(/#{Regexp.escape(w)}/m)
  8. end
  9. end
  10. context 'concat gnu parameter' do
  11. pp = <<-EOS
  12. concat { '#{basedir}/file':
  13. gnu => 'foo',
  14. }
  15. concat::fragment { 'foo':
  16. target => '#{basedir}/file',
  17. content => 'bar',
  18. }
  19. EOS
  20. w = 'The $gnu parameter to concat is deprecated and has no effect'
  21. it_behaves_like 'has_warning', pp, w
  22. end
  23. context 'concat warn parameter =>' do
  24. ['true', 'yes', 'on'].each do |warn|
  25. context warn do
  26. pp = <<-EOS
  27. concat { '#{basedir}/file':
  28. warn => '#{warn}',
  29. }
  30. concat::fragment { 'foo':
  31. target => '#{basedir}/file',
  32. content => 'bar',
  33. }
  34. EOS
  35. w = 'Using stringified boolean values (\'true\', \'yes\', \'on\', \'false\', \'no\', \'off\') to represent boolean true/false as the $warn parameter to concat is deprecated and will be treated as the warning message in a future release'
  36. it_behaves_like 'has_warning', pp, w
  37. describe file("#{basedir}/file") do
  38. it { should be_file }
  39. it { should contain '# This file is managed by Puppet. DO NOT EDIT.' }
  40. it { should contain 'bar' }
  41. end
  42. end
  43. end
  44. ['false', 'no', 'off'].each do |warn|
  45. context warn do
  46. pp = <<-EOS
  47. concat { '#{basedir}/file':
  48. warn => '#{warn}',
  49. }
  50. concat::fragment { 'foo':
  51. target => '#{basedir}/file',
  52. content => 'bar',
  53. }
  54. EOS
  55. w = 'Using stringified boolean values (\'true\', \'yes\', \'on\', \'false\', \'no\', \'off\') to represent boolean true/false as the $warn parameter to concat is deprecated and will be treated as the warning message in a future release'
  56. it_behaves_like 'has_warning', pp, w
  57. describe file("#{basedir}/file") do
  58. it { should be_file }
  59. it { should_not contain '# This file is managed by Puppet. DO NOT EDIT.' }
  60. it { should contain 'bar' }
  61. end
  62. end
  63. end
  64. end
  65. context 'concat::fragment ensure parameter', :unless => fact('osfamily') == 'windows' do
  66. context 'target file exists' do
  67. before(:all) do
  68. pp = <<-EOS
  69. file { '#{basedir}':
  70. ensure => directory,
  71. }
  72. file { '#{basedir}/file1':
  73. content => "file1 contents\n",
  74. }
  75. EOS
  76. apply_manifest(pp)
  77. end
  78. pp = <<-EOS
  79. concat { '#{basedir}/file': }
  80. concat::fragment { 'foo':
  81. target => '#{basedir}/file',
  82. ensure => '#{basedir}/file1',
  83. }
  84. EOS
  85. w = 'Passing a value other than \'present\' or \'absent\' as the $ensure parameter to concat::fragment is deprecated. If you want to use the content of a file as a fragment please use the $source parameter.'
  86. it_behaves_like 'has_warning', pp, w
  87. describe file("#{basedir}/file") do
  88. it { should be_file }
  89. it { should contain 'file1 contents' }
  90. end
  91. describe 'the fragment can be changed from a symlink to a plain file', :unless => (fact("osfamily") == "windows") do
  92. pp = <<-EOS
  93. concat { '#{basedir}/file': }
  94. concat::fragment { 'foo':
  95. target => '#{basedir}/file',
  96. content => 'new content',
  97. }
  98. EOS
  99. it 'applies the manifest twice with no stderr' do
  100. apply_manifest(pp, :catch_failures => true)
  101. apply_manifest(pp, :catch_changes => true)
  102. end
  103. describe file("#{basedir}/file") do
  104. it { should be_file }
  105. it { should contain 'new content' }
  106. it { should_not contain 'file1 contents' }
  107. end
  108. end
  109. end # target file exists
  110. context 'target does not exist', :unless => fact('osfamily') == 'windows' do
  111. pp = <<-EOS
  112. concat { '#{basedir}/file': }
  113. concat::fragment { 'foo':
  114. target => '#{basedir}/file',
  115. ensure => '#{basedir}/file1',
  116. }
  117. EOS
  118. w = 'Passing a value other than \'present\' or \'absent\' as the $ensure parameter to concat::fragment is deprecated. If you want to use the content of a file as a fragment please use the $source parameter.'
  119. it_behaves_like 'has_warning', pp, w
  120. describe file("#{basedir}/file") do
  121. it { should be_file }
  122. end
  123. describe 'the fragment can be changed from a symlink to a plain file', :unless => (fact('osfamily') == 'windows') do
  124. pp = <<-EOS
  125. concat { '#{basedir}/file': }
  126. concat::fragment { 'foo':
  127. target => '#{basedir}/file',
  128. content => 'new content',
  129. }
  130. EOS
  131. it 'applies the manifest twice with no stderr' do
  132. apply_manifest(pp, :catch_failures => true)
  133. apply_manifest(pp, :catch_changes => true)
  134. end
  135. describe file("#{basedir}/file") do
  136. it { should be_file }
  137. it { should contain 'new content' }
  138. end
  139. end
  140. end # target file exists
  141. end # concat::fragment ensure parameter
  142. context 'concat::fragment mode parameter' do
  143. pp = <<-EOS
  144. concat { '#{basedir}/file': }
  145. concat::fragment { 'foo':
  146. target => '#{basedir}/file',
  147. content => 'bar',
  148. mode => 'bar',
  149. }
  150. EOS
  151. w = 'The $mode parameter to concat::fragment is deprecated and has no effect'
  152. it_behaves_like 'has_warning', pp, w
  153. end
  154. context 'concat::fragment owner parameter' do
  155. pp = <<-EOS
  156. concat { '#{basedir}/file': }
  157. concat::fragment { 'foo':
  158. target => '#{basedir}/file',
  159. content => 'bar',
  160. owner => 'bar',
  161. }
  162. EOS
  163. w = 'The $owner parameter to concat::fragment is deprecated and has no effect'
  164. it_behaves_like 'has_warning', pp, w
  165. end
  166. context 'concat::fragment group parameter' do
  167. pp = <<-EOS
  168. concat { '#{basedir}/file': }
  169. concat::fragment { 'foo':
  170. target => '#{basedir}/file',
  171. content => 'bar',
  172. group => 'bar',
  173. }
  174. EOS
  175. w = 'The $group parameter to concat::fragment is deprecated and has no effect'
  176. it_behaves_like 'has_warning', pp, w
  177. end
  178. context 'concat::fragment backup parameter' do
  179. pp = <<-EOS
  180. concat { '#{basedir}/file': }
  181. concat::fragment { 'foo':
  182. target => '#{basedir}/file',
  183. content => 'bar',
  184. backup => 'bar',
  185. }
  186. EOS
  187. w = 'The $backup parameter to concat::fragment is deprecated and has no effect'
  188. it_behaves_like 'has_warning', pp, w
  189. end
  190. context 'include concat::setup' do
  191. pp = <<-EOS
  192. include concat::setup
  193. EOS
  194. w = 'concat::setup is deprecated as a public API of the concat module and should no longer be directly included in the manifest.'
  195. it_behaves_like 'has_warning', pp, w
  196. end
  197. end