PageRenderTime 26ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/puphpet/puppet/modules/mongodb/spec/classes/server_config_spec.rb

https://gitlab.com/my-application.bjoernbartels.earth/application-base
Ruby | 159 lines | 121 code | 37 blank | 1 comment | 0 complexity | e286794b03d36ebf335f110a1af1f3d2 MD5 | raw file
  1. require 'spec_helper'
  2. describe 'mongodb::server::config', :type => :class do
  3. describe 'with preseted variables' do
  4. let(:pre_condition) { ["class mongodb::server { $config = '/etc/mongod.conf' $dbpath = '/var/lib/mongo' $rcfile = '/root/.mongorc.js' }", "include mongodb::server"]}
  5. it {
  6. is_expected.to contain_file('/etc/mongod.conf')
  7. }
  8. end
  9. describe 'with default values' do
  10. let(:pre_condition) {[ "class mongodb::server { $config = '/etc/mongod.conf' $dbpath = '/var/lib/mongo' $create_admin = false $rcfile = '/root/.mongorc.js' $store_creds = true $ensure = present $user = 'mongod' $group = 'mongod' $port = 29017 $bind_ip = ['0.0.0.0'] $fork = true $logpath ='/var/log/mongo/mongod.log' $logappend = true }", "include mongodb::server" ]}
  11. it {
  12. is_expected.to contain_file('/etc/mongod.conf').with({
  13. :mode => '0644',
  14. :owner => 'root',
  15. :group => 'root'
  16. })
  17. is_expected.to contain_file('/etc/mongod.conf').with_content(/^dbpath=\/var\/lib\/mongo/)
  18. is_expected.to contain_file('/etc/mongod.conf').with_content(/bind_ip\s=\s0\.0\.0\.0/)
  19. is_expected.to contain_file('/etc/mongod.conf').with_content(/^port = 29017$/)
  20. is_expected.to contain_file('/etc/mongod.conf').with_content(/^logappend=true/)
  21. is_expected.to contain_file('/etc/mongod.conf').with_content(/^logpath=\/var\/log\/mongo\/mongod\.log/)
  22. is_expected.to contain_file('/etc/mongod.conf').with_content(/^fork=true/)
  23. is_expected.to contain_file('/root/.mongorc.js').with({ :ensure => 'absent' })
  24. }
  25. end
  26. describe 'with absent ensure' do
  27. let(:pre_condition) { ["class mongodb::server { $config = '/etc/mongod.conf' $dbpath = '/var/lib/mongo' $rcfile = '/root/.mongorc.js' $ensure = absent }", "include mongodb::server"]}
  28. it {
  29. is_expected.to contain_file('/etc/mongod.conf').with({ :ensure => 'absent' })
  30. }
  31. end
  32. describe 'when specifying storage_engine' do
  33. let(:pre_condition) { ["class mongodb::server { $config = '/etc/mongod.conf' $dbpath = '/var/lib/mongo' $rcfile = '/root/.monogrc.js' $ensure = present $version='3.0.3' $storage_engine = 'SomeEngine' $storage_engine_internal = 'SomeEngine' $user = 'mongod' $group = 'mongod' $port = 29017 $bind_ip = ['0.0.0.0'] $fork = true $logpath ='/var/log/mongo/mongod.log' $logappend = true}", "include mongodb::server"]}
  34. it {
  35. is_expected.to contain_file('/etc/mongod.conf').with_content(/storage.engine:\sSomeEngine/)
  36. }
  37. end
  38. describe 'with specific bind_ip values and ipv6' do
  39. let(:pre_condition) { ["class mongodb::server { $config = '/etc/mongod.conf' $dbpath = '/var/lib/mongo' $rcfile = '/root/.mongorc.js' $ensure = present $bind_ip = ['127.0.0.1', 'fd00:beef:dead:55::143'] $ipv6 = true }", "include mongodb::server"]}
  40. it {
  41. is_expected.to contain_file('/etc/mongod.conf').with_content(/bind_ip\s=\s127\.0\.0\.1\,fd00:beef:dead:55::143/)
  42. is_expected.to contain_file('/etc/mongod.conf').with_content(/ipv6=true/)
  43. }
  44. end
  45. describe 'with specific bind_ip values' do
  46. let(:pre_condition) { ["class mongodb::server { $config = '/etc/mongod.conf' $dbpath = '/var/lib/mongo' $rcfile = '/root/.mongorc.js' $ensure = present $bind_ip = ['127.0.0.1', '10.1.1.13']}", "include mongodb::server"]}
  47. it {
  48. is_expected.to contain_file('/etc/mongod.conf').with_content(/bind_ip\s=\s127\.0\.0\.1\,10\.1\.1\.13/)
  49. }
  50. end
  51. describe 'when specifying auth to true' do
  52. let(:pre_condition) { ["class mongodb::server { $config = '/etc/mongod.conf' $auth = true $dbpath = '/var/lib/mongo' $rcfile = '/root/.mongorc.js' $ensure = present }", "include mongodb::server"]}
  53. it {
  54. is_expected.to contain_file('/etc/mongod.conf').with_content(/^auth=true/)
  55. is_expected.to contain_file('/root/.mongorc.js')
  56. }
  57. end
  58. describe 'when specifying set_parameter value' do
  59. let(:pre_condition) { ["class mongodb::server { $config = '/etc/mongod.conf' $set_parameter = 'textSearchEnable=true' $dbpath = '/var/lib/mongo' $rcfile = '/root/.mongorc.js' $ensure = present }", "include mongodb::server"]}
  60. it {
  61. is_expected.to contain_file('/etc/mongod.conf').with_content(/^setParameter = textSearchEnable=true/)
  62. }
  63. end
  64. describe 'with journal:' do
  65. context 'on true with i686 architecture' do
  66. let(:pre_condition) { ["class mongodb::server { $config = '/etc/mongod.conf' $dbpath = '/var/lib/mongo' $rcfile = '/root/.mongorc.js' $ensure = present $journal = true }", "include mongodb::server"]}
  67. let (:facts) { { :architecture => 'i686' } }
  68. it {
  69. is_expected.to contain_file('/etc/mongod.conf').with_content(/^journal = true/)
  70. }
  71. end
  72. end
  73. # check nested quota and quotafiles
  74. describe 'with quota to' do
  75. context 'true and without quotafiles' do
  76. let(:pre_condition) { ["class mongodb::server { $config = '/etc/mongod.conf' $dbpath = '/var/lib/mongo' $rcfile = '/root/.mongorc.js' $ensure = present $quota = true }", "include mongodb::server"]}
  77. it {
  78. is_expected.to contain_file('/etc/mongod.conf').with_content(/^quota = true/)
  79. }
  80. end
  81. context 'true and with quotafiles' do
  82. let(:pre_condition) { ["class mongodb::server { $config = '/etc/mongod.conf' $dbpath = '/var/lib/mongo' $rcfile = '/root/.mongorc.js' $ensure = present $quota = true $quotafiles = 1 }", "include mongodb::server"]}
  83. it {
  84. is_expected.to contain_file('/etc/mongod.conf').with_content(/quota = true/)
  85. is_expected.to contain_file('/etc/mongod.conf').with_content(/quotaFiles = 1/)
  86. }
  87. end
  88. end
  89. describe 'when specifying syslog value' do
  90. context 'it should be set to true' do
  91. let(:pre_condition) { ["class mongodb::server { $config = '/etc/mongod.conf' $dbpath = '/var/lib/mongo' $rcfile = '/root/.mongorc.js' $ensure = present $syslog = true }", "include mongodb::server"]}
  92. it {
  93. is_expected.to contain_file('/etc/mongod.conf').with_content(/^syslog = true/)
  94. }
  95. end
  96. context 'if logpath is also set an error should be raised' do
  97. let(:pre_condition) { ["class mongodb::server { $config = '/etc/mongod.conf' $dbpath = '/var/lib/mongo' $rcfile = '/root/.mongorc.js' $ensure = present $syslog = true $logpath ='/var/log/mongo/mongod.log' }", "include mongodb::server"]}
  98. it {
  99. expect { is_expected.to contain_file('/etc/mongod.conf') }.to raise_error(Puppet::Error, /You cannot use syslog with logpath/)
  100. }
  101. end
  102. end
  103. describe 'with store_creds' do
  104. context 'true' do
  105. let(:pre_condition) { ["class mongodb::server { $admin_username = 'admin' $admin_password = 'password' $auth = true $store_creds = true $config = '/etc/mongod.conf' $dbpath = '/var/lib/mongo' $rcfile = '/root/.mongorc.js' $ensure = present }", "include mongodb::server"]}
  106. it {
  107. is_expected.to contain_file('/root/.mongorc.js').
  108. with_ensure('present').
  109. with_owner('root').
  110. with_group('root').
  111. with_mode('0644').
  112. with_content(/db.auth\('admin', 'password'\)/)
  113. }
  114. end
  115. context 'false' do
  116. let(:pre_condition) { ["class mongodb::server { $config = '/etc/mongod.conf' $dbpath = '/var/lib/mongo' $rcfile = '/root/.mongorc.js' $ensure = present $store_creds = false }", "include mongodb::server"]}
  117. it {
  118. is_expected.to contain_file('/root/.mongorc.js').with_ensure('absent')
  119. }
  120. end
  121. end
  122. end