Skip to content

Commit

Permalink
SIRE-9538 fix spec tests
Browse files Browse the repository at this point in the history
Reviewed-by: muspelkat, beilers
  • Loading branch information
Henning-B committed Jun 20, 2023
1 parent 338bd62 commit 9f0f0de
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/puppet/provider/mongodb_database/mongodb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def self.instances
catch (err) {
rs.slaveOk()
}
'
'.squeeze(" ")

Check failure on line 25 in lib/puppet/provider/mongodb_database/mongodb.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. (https://rubystyle.guide#consistent-string-literals)
mongo_eval_result = mongo_eval("#{pre_cmd};JSON.stringify(db.getMongo().getDBs())")
dbs = JSON.parse mongo_eval_result

Expand Down
13 changes: 11 additions & 2 deletions spec/acceptance/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
service_name = 'mongod'
package_name = 'mongodb-org-server'
end
major_version=fact('mongodb_version').split('.')[0].to_i

Check failure on line 28 in spec/acceptance/server_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Layout/SpaceAroundOperators: Surrounding space missing for operator `=`. (https://rubystyle.guide#spaces-operators)
if major_version>=5

Check failure on line 29 in spec/acceptance/server_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Style/ConditionalAssignment: Use the return of the conditional for variable assignment and comparison.

Check failure on line 29 in spec/acceptance/server_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Layout/SpaceAroundOperators: Surrounding space missing for operator `>=`. (https://rubystyle.guide#spaces-operators)
mongo_cli=mongosh

Check failure on line 30 in spec/acceptance/server_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Layout/SpaceAroundOperators: Surrounding space missing for operator `=`. (https://rubystyle.guide#spaces-operators)
else
mongo_cli=mongo

Check failure on line 32 in spec/acceptance/server_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Layout/SpaceAroundOperators: Surrounding space missing for operator `=`. (https://rubystyle.guide#spaces-operators)
end


Check failure on line 35 in spec/acceptance/server_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Layout/EmptyLines: Extra blank line detected. (https://rubystyle.guide#two-or-more-empty-lines)
describe 'installation' do
it 'works with no errors' do
Expand Down Expand Up @@ -143,15 +150,17 @@ class { 'mongodb::client': }
its(:stdout) { is_expected.to match '13' }
end

describe file('/root/.mongorc.js') do

Check failure on line 153 in spec/acceptance/server_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Layout/EmptyLines: Extra blank line detected. (https://rubystyle.guide#two-or-more-empty-lines)

Check failure on line 154 in spec/acceptance/server_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Layout/EmptyLines: Extra blank line detected. (https://rubystyle.guide#two-or-more-empty-lines)
describe file("/root/.#{mongo_cli}.js") do
it { is_expected.to be_file }
it { is_expected.to be_owned_by 'root' }
it { is_expected.to be_grouped_into 'root' }
it { is_expected.to be_mode 600 }
it { is_expected.to contain 'db.auth(\'admin\', \'password\')' }
end

describe command("mongo admin --quiet --eval \"load('/root/.mongorc.js');printjson(db.getUser('admin')['customData'])\"") do
describe command("#{mongo_cli} admin --quiet --eval \"load('/root/.#{mongo_cli}.js');printjson(db.getUser('admin')['customData'])\"") do
its(:exit_status) { is_expected.to eq 0 }
its(:stdout) { is_expected.to match "{ \"createdBy\" : \"Puppet Mongodb_user['User admin on db admin']\" }\n" }
end
Expand Down
16 changes: 15 additions & 1 deletion spec/unit/puppet/provider/mongodb_database/mongodb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,21 @@
tmp = Tempfile.new('test')
mongodconffile = tmp.path
allow(provider.class).to receive(:mongod_conf_file).and_return(mongodconffile)
allow(provider.class).to receive(:mongo_eval).with('try { rs.secondaryOk() } catch (err) { rs.slaveOk() };printjson(db.getMongo().getDBs())').and_return(raw_dbs)
mongodb_eval_command = '
try {
version=parseInt(db.version().split(\'.\')[0])
if (version>=5){
db.getMongo().setReadPref(\'nearest\')
}
else{
rs.secondaryOk()
}
}
catch (err) {
rs.slaveOk()
}
;JSON.stringify(db.getMongo().getDBs())'.squeeze(" ")

Check failure on line 54 in spec/unit/puppet/provider/mongodb_database/mongodb_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols. (https://rubystyle.guide#consistent-string-literals)
allow(provider.class).to receive(:mongo_eval).with(mongodb_eval_command).and_return(raw_dbs)
allow(provider.class).to receive(:db_ismaster).and_return(true)
end

Expand Down

0 comments on commit 9f0f0de

Please sign in to comment.