ini_subsetting_spec.rb 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. require 'spec_helper_acceptance'
  2. tmpdir = default.tmpdir('tmp')
  3. describe 'ini_subsetting resource' do
  4. after :all do
  5. shell("rm #{tmpdir}/*.ini", :acceptable_exit_codes => [0,1,2])
  6. end
  7. shared_examples 'has_content' do |path,pp,content|
  8. before :all do
  9. shell("rm #{path}", :acceptable_exit_codes => [0,1,2])
  10. end
  11. after :all do
  12. shell("cat #{path}", :acceptable_exit_codes => [0,1,2])
  13. shell("rm #{path}", :acceptable_exit_codes => [0,1,2])
  14. end
  15. it 'applies the manifest twice with no stderr' do
  16. expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("")
  17. expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("")
  18. end
  19. describe file(path) do
  20. it { should be_file }
  21. it { should contain(content) }
  22. end
  23. end
  24. shared_examples 'has_error' do |path,pp,error|
  25. before :all do
  26. shell("rm #{path}", :acceptable_exit_codes => [0,1,2])
  27. end
  28. after :all do
  29. shell("cat #{path}", :acceptable_exit_codes => [0,1,2])
  30. shell("rm #{path}", :acceptable_exit_codes => [0,1,2])
  31. end
  32. it 'applies the manifest and gets a failure message' do
  33. expect(apply_manifest(pp, :expect_failures => true).stderr).to match(error)
  34. end
  35. describe file(path) do
  36. it { should_not be_file }
  37. end
  38. end
  39. describe 'ensure, section, setting, subsetting, & value parameters' do
  40. context '=> present with subsections' do
  41. pp = <<-EOS
  42. ini_subsetting { 'ensure => present for alpha':
  43. ensure => present,
  44. path => "#{tmpdir}/ini_subsetting.ini",
  45. section => 'one',
  46. setting => 'key',
  47. subsetting => 'alpha',
  48. value => 'bet',
  49. }
  50. ini_subsetting { 'ensure => present for beta':
  51. ensure => present,
  52. path => "#{tmpdir}/ini_subsetting.ini",
  53. section => 'one',
  54. setting => 'key',
  55. subsetting => 'beta',
  56. value => 'trons',
  57. }
  58. EOS
  59. it 'applies the manifest twice with no stderr' do
  60. expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("")
  61. expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("")
  62. end
  63. describe file("#{tmpdir}/ini_subsetting.ini") do
  64. it { should be_file }
  65. #XXX Solaris 10 doesn't support multi-line grep
  66. it("should contain [one]\nkey = alphabet betatrons", :unless => fact('osfamily') == 'Solaris') {
  67. should contain("[one]\nkey = alphabet betatrons")
  68. }
  69. end
  70. end
  71. context 'ensure => absent' do
  72. before :all do
  73. shell("echo -e \"[one]\nkey = alphabet betatrons\" > #{tmpdir}/ini_subsetting.ini")
  74. end
  75. pp = <<-EOS
  76. ini_subsetting { 'ensure => absent for subsetting':
  77. ensure => absent,
  78. path => "#{tmpdir}/ini_subsetting.ini",
  79. section => 'one',
  80. setting => 'key',
  81. subsetting => 'alpha',
  82. }
  83. EOS
  84. it 'applies the manifest twice with no stderr' do
  85. expect(apply_manifest(pp, :catch_failures => true).stderr).to eq("")
  86. expect(apply_manifest(pp, :catch_changes => true).stderr).to eq("")
  87. end
  88. describe file("#{tmpdir}/ini_subsetting.ini") do
  89. it { should be_file }
  90. it { should contain('[one]') }
  91. it { should contain('key = betatrons') }
  92. it { should_not contain('alphabet') }
  93. end
  94. end
  95. end
  96. describe 'subsetting_separator' do
  97. {
  98. "" => "two = twinethree foobar",
  99. #"subsetting_separator => ''," => "two = twinethreefoobar", # breaks regex
  100. "subsetting_separator => ','," => "two = twinethree,foobar",
  101. "subsetting_separator => ' '," => "two = twinethree foobar",
  102. "subsetting_separator => ' == '," => "two = twinethree == foobar",
  103. "subsetting_separator => '='," => "two = twinethree=foobar",
  104. #"subsetting_separator => '---'," => "two = twinethree---foobar", # breaks regex
  105. }.each do |parameter, content|
  106. context "with \"#{parameter}\" makes \"#{content}\"" do
  107. pp = <<-EOS
  108. ini_subsetting { "with #{parameter} makes #{content}":
  109. ensure => present,
  110. section => 'one',
  111. setting => 'two',
  112. subsetting => 'twine',
  113. value => 'three',
  114. path => "#{tmpdir}/subsetting_separator.ini",
  115. #{parameter}
  116. }
  117. ini_subsetting { "foobar":
  118. ensure => present,
  119. section => 'one',
  120. setting => 'two',
  121. subsetting => 'foo',
  122. value => 'bar',
  123. path => "#{tmpdir}/subsetting_separator.ini",
  124. #{parameter}
  125. }
  126. EOS
  127. it_behaves_like 'has_content', "#{tmpdir}/subsetting_separator.ini", pp, content
  128. end
  129. end
  130. end
  131. end