init_spec.rb 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. require 'spec_helper'
  2. describe 'inifile' do
  3. describe 'with default options' do
  4. it { should compile.with_all_deps }
  5. it { should contain_class('inifile') }
  6. end
  7. describe 'with parameter ini_settings_hiera_merge' do
  8. context 'set to an invalid type (non-string and a non-boolean)' do
  9. let(:params) { { :ini_settings_hiera_merge => ['invalid','type'] } }
  10. it 'should fail' do
  11. expect {
  12. should contain_class('inifile')
  13. }.to raise_error(Puppet::Error,/\["invalid", "type"\] is not a boolean./)
  14. end
  15. end
  16. ['true',true,'false',false].each do |value|
  17. context "set to #{value}" do
  18. let(:params) { { :ini_settings_hiera_merge => value } }
  19. it { should contain_class('inifile') }
  20. end
  21. end
  22. end
  23. describe 'with parameter ini_settings' do
  24. context 'set to an invalid type (non-hash)' do
  25. let(:params) do
  26. {
  27. :ini_settings => ['invalid','type'],
  28. :ini_settings_hiera_merge => false,
  29. }
  30. end
  31. it 'should fail' do
  32. expect {
  33. should contain_class('inifile')
  34. }.to raise_error(Puppet::Error,/\["invalid", "type"\] is not a Hash./)
  35. end
  36. end
  37. context 'set to a valid hash' do
  38. let(:params) { { :ini_settings_hiera_merge => false,
  39. :ini_settings => {
  40. 'sample setting' => {
  41. 'ensure' => 'absent',
  42. 'path' => '/tmp/foo.ini',
  43. 'section' => 'foo',
  44. 'setting' => 'foosetting',
  45. 'value' => 'FOO!',
  46. },
  47. 'colorize_git' => {
  48. 'ensure' => 'present',
  49. 'path' => '/root/.gitconfig',
  50. 'section' => 'color',
  51. 'setting' => 'ui',
  52. 'value' => 'auto',
  53. }
  54. } } }
  55. it { should contain_class('inifile') }
  56. it {
  57. should contain_ini_setting('sample setting').with({
  58. 'ensure' => 'absent',
  59. 'path' => '/tmp/foo.ini',
  60. 'section' => 'foo',
  61. 'setting' => 'foosetting',
  62. 'value' => 'FOO!',
  63. })
  64. }
  65. it {
  66. should contain_ini_setting('colorize_git').with({
  67. 'ensure' => 'present',
  68. 'path' => '/root/.gitconfig',
  69. 'section' => 'color',
  70. 'setting' => 'ui',
  71. 'value' => 'auto',
  72. })
  73. }
  74. end
  75. end
  76. describe 'with parameter ini_subsettings_hiera_merge' do
  77. context 'set to an invalid type (non-string and a non-boolean)' do
  78. let(:params) { { :ini_subsettings_hiera_merge => ['invalid','type'] } }
  79. it 'should fail' do
  80. expect {
  81. should contain_class('inifile')
  82. }.to raise_error(Puppet::Error,/\["invalid", "type"\] is not a boolean./)
  83. end
  84. end
  85. ['true',true,'false',false].each do |value|
  86. context "set to #{value}" do
  87. let(:params) { { :ini_subsettings_hiera_merge => value } }
  88. it { should contain_class('inifile') }
  89. end
  90. end
  91. end
  92. describe 'with parameter ini_subsettings' do
  93. context 'set to an invalid type (non-hash)' do
  94. let(:params) do
  95. {
  96. :ini_subsettings => ['invalid','type'],
  97. :ini_subsettings_hiera_merge => false,
  98. }
  99. end
  100. it 'should fail' do
  101. expect {
  102. should contain_class('inifile')
  103. }.to raise_error(Puppet::Error,/\["invalid", "type"\] is not a Hash./)
  104. end
  105. end
  106. context 'set to a valid hash' do
  107. let(:params) { { :ini_subsettings_hiera_merge => false,
  108. :ini_subsettings => {
  109. 'sample setting' => {
  110. 'ensure' => 'absent',
  111. 'path' => '/tmp/foo.ini',
  112. 'section' => 'foo',
  113. 'setting' => 'foosetting',
  114. 'value' => 'FOO!',
  115. },
  116. 'colorize_git' => {
  117. 'ensure' => 'present',
  118. 'path' => '/root/.gitconfig',
  119. 'section' => 'color',
  120. 'setting' => 'ui',
  121. 'value' => 'auto',
  122. }
  123. } } }
  124. it { should contain_class('inifile') }
  125. it {
  126. should contain_ini_subsetting('sample setting').with({
  127. 'ensure' => 'absent',
  128. 'path' => '/tmp/foo.ini',
  129. 'section' => 'foo',
  130. 'setting' => 'foosetting',
  131. 'value' => 'FOO!',
  132. })
  133. }
  134. it {
  135. should contain_ini_subsetting('colorize_git').with({
  136. 'ensure' => 'present',
  137. 'path' => '/root/.gitconfig',
  138. 'section' => 'color',
  139. 'setting' => 'ui',
  140. 'value' => 'auto',
  141. })
  142. }
  143. end
  144. end
  145. end