Skip to content

Commit

Permalink
[Acceptance] Use bott new mongosh and mongoshrc
Browse files Browse the repository at this point in the history
  • Loading branch information
Johan De Wit committed Jul 11, 2023
1 parent 37c8a5a commit 0e76831
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 29 deletions.
8 changes: 4 additions & 4 deletions spec/acceptance/database_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class { 'mongodb::server': }
end

it 'creates the databases' do
shell("mongo testdb1 --eval 'EJSON.stringify(db.getMongo().getDBs())'")
shell("mongo testdb2 --eval 'EJSON.stringify(db.getMongo().getDBs())'")
shell("mongosh testdb1 --eval 'EJSON.stringify(db.getMongo().getDBs())'")
shell("mongsho testdb2 --eval 'EJSON.stringify(db.getMongo().getDBs())'")
end
end

Expand All @@ -50,8 +50,8 @@ class { 'mongodb::server':
end

it 'creates the database' do
shell("mongo testdb1 --port 27018 --eval 'EJSON.stringify(db.getMongo().getDBs())'")
shell("mongo testdb2 --port 27018 --eval 'EJSON.stringify(db.getMongo().getDBs())'")
shell("mongosh testdb1 --port 27018 --eval 'EJSON.stringify(db.getMongo().getDBs())'")
shell("mongosh testdb2 --port 27018 --eval 'EJSON.stringify(db.getMongo().getDBs())'")
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/acceptance/mongos_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class { 'mongodb::server':
it { is_expected.to be_listening }
end

describe command('mongo --version') do
describe command('mongod --version') do
its(:exit_status) { is_expected.to eq 0 }
end
end
Expand Down
20 changes: 10 additions & 10 deletions spec/acceptance/replset_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
describe 'mongodb_replset resource' do
after :all do
# Have to drop the DB to disable replsets for further testing
on hosts, %{mongo local --verbose --eval 'db.dropDatabase()'}
on hosts, %{mongosh local --verbose --eval 'db.dropDatabase()'}

pp = <<-EOS
class { 'mongodb::globals': }
Expand Down Expand Up @@ -48,26 +48,26 @@ class { 'mongodb::client': }
}
EOS
apply_manifest_on(hosts_as('master'), pp, catch_failures: true)
on(hosts_as('master'), 'mongo --quiet --eval "EJSON.stringify(rs.conf())"') do |r|
on(hosts_as('master'), 'mongosh --quiet --eval "EJSON.stringify(rs.conf())"') do |r|
expect(r.stdout).to match %r{#{hosts[0]}:27017}
expect(r.stdout).to match %r{#{hosts[1]}:27017}
end
end

it 'inserts data on the master' do
sleep(30)
on hosts_as('master'), %{mongo --verbose --eval 'db.test.save({name:"test1",value:"some value"})'}
on hosts_as('master'), %{mongosh --verbose --eval 'db.test.save({name:"test1",value:"some value"})'}
end

it 'checks the data on the master' do
on hosts_as('master'), %{mongo --verbose --eval 'EJSON.stringify(db.test.findOne({name:"test1"}))'} do |r|
on hosts_as('master'), %{mongosh --verbose --eval 'EJSON.stringify(db.test.findOne({name:"test1"}))'} do |r|
expect(r.stdout).to match %r{some value}
end
end

it 'checks the data on the slave' do
sleep(10)
on hosts_as('slave'), %{mongo --verbose --eval 'db.getMongo().setReadPref("primaryPreferred"); EJSON.stringify(db.test.findOne({name:"test1"}))'} do |r|
on hosts_as('slave'), %{mongosh --verbose --eval 'db.getMongo().setReadPref("primaryPreferred"); EJSON.stringify(db.test.findOne({name:"test1"}))'} do |r|
expect(r.stdout).to match %r{some value}
end
end
Expand All @@ -76,7 +76,7 @@ class { 'mongodb::client': }
describe 'mongodb_replset resource with auth => true' do
after :all do
# Have to drop the DB to disable replsets for further testing
on hosts, %{mongo local --verbose --eval 'db.dropDatabase()'}
on hosts, %{mongosh local --verbose --eval 'db.dropDatabase()'}

pp = <<-EOS
class { 'mongodb::globals': }
Expand Down Expand Up @@ -177,26 +177,26 @@ class { 'mongodb::server':
EOS
apply_manifest_on(hosts_as('master'), pp, catch_failures: true)
apply_manifest_on(hosts_as('master'), pp, catch_changes: true)
on(hosts_as('master'), 'mongo --quiet --eval "load(\'/root/.mongoshrc.js\');EJSON.stringify(rs.conf())"') do |r|
on(hosts_as('master'), 'mongosh --quiet --eval "load(\'/root/.mongoshrc.js\');EJSON.stringify(rs.conf())"') do |r|
expect(r.stdout).to match %r{#{hosts[0]}:27017}
expect(r.stdout).to match %r{#{hosts[1]}:27017}
end
end

it 'inserts data on the master' do
sleep(30)
on hosts_as('master'), %{mongo test --verbose --eval 'load("/root/.mongoshrc.js");db.dummyData.insert({"created_by_puppet": 1})'}
on hosts_as('master'), %{mongosh test --verbose --eval 'load("/root/.mongoshrc.js");db.dummyData.insert({"created_by_puppet": 1})'}
end

it 'checks the data on the master' do
on hosts_as('master'), %{mongo test --verbose --eval 'load("/root/.mongoshrc.js");EJSON.stringify(db.dummyData.findOne())'} do |r|
on hosts_as('master'), %{mongosh test --verbose --eval 'load("/root/.mongoshrc.js");EJSON.stringify(db.dummyData.findOne())'} do |r|
expect(r.stdout).to match %r{created_by_puppet}
end
end

it 'checks the data on the slave' do
sleep(10)
on hosts_as('slave'), %{mongo test --verbose --eval 'load("/root/.mongoshrc.js");db.getMongo().setReadPref("primaryPreferred");EJSON.stringify(db.dummyData.findOne())'} do |r|
on hosts_as('slave'), %{mongosh test --verbose --eval 'load("/root/.mongoshrc.js");db.getMongo().setReadPref("primaryPreferred");EJSON.stringify(db.dummyData.findOne())'} do |r|
expect(r.stdout).to match %r{created_by_puppet}
end
end
Expand Down
10 changes: 5 additions & 5 deletions spec/acceptance/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class { 'mongodb::server': }
it { is_expected.to be_listening }
end

describe command('mongo --version') do
describe command('mongod --version') do
its(:exit_status) { is_expected.to eq 0 }
end
end
Expand Down Expand Up @@ -139,24 +139,24 @@ class { 'mongodb::client': }
it { is_expected.to be_listening }
end

describe command('mongo --quiet --eval "db.serverCmdLineOpts().code"') do
describe command('mongosh --quiet --eval "db.serverCmdLineOpts().code"') do
its(:stdout) { is_expected.to match '13' }
end

describe file('/root/.mongorc.js') do
describe file('/root/.mongoshrc.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');EJSON.stringify(db.getUser('admin')['customData'])\"") do
describe command("mongosh admin --quiet --eval \"load('/root/.mongoshrc.js');EJSON.stringify(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

describe command('mongo --version') do
describe command('mongod --version') do
its(:exit_status) { is_expected.to eq 0 }
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/acceptance/sharding_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class { 'mongodb::client': }
EOS

apply_manifest_on(hosts_as('router'), pp, catch_failures: true)
on(hosts_as('router'), 'mongo --quiet --eval "EJSON.stringify(sh.status())"') do |r|
on(hosts_as('router'), 'mongosh --quiet --eval "EJSON.stringify(sh.status())"') do |r|
expect(r.stdout).to match %r{foo/shard:27018}
expect(r.stdout).to match %r{foo\.toto}
end
Expand Down
16 changes: 8 additions & 8 deletions spec/acceptance/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class { 'mongodb::server': }
end

it 'creates the user' do
shell("mongo testdb --quiet --eval 'db.auth(\"testuser\",\"passw0rd\")'") do |r|
shell("mongosh testdb --quiet --eval 'db.auth(\"testuser\",\"passw0rd\")'") do |r|
expect(r.stdout.chomp).to eq('1')
end
end
Expand All @@ -45,7 +45,7 @@ class { 'mongodb::server': }
end

it 'auth should fail' do
shell("mongo testdb --quiet --eval 'db.auth(\"testuser\",\"passw0rd\")'") do |r|
shell("mongosh testdb --quiet --eval 'db.auth(\"testuser\",\"passw0rd\")'") do |r|
expect(r.stdout.chomp).to contain('Error: Authentication failed')
end
end
Expand All @@ -70,7 +70,7 @@ class { 'mongodb::server': port => 27018 }
end

it 'creates the user' do
shell("mongo testdb --quiet --port 27018 --eval 'db.auth(\"testuser\",\"passw0rd\")'") do |r|
shell("mongosh testdb --quiet --port 27018 --eval 'db.auth(\"testuser\",\"passw0rd\")'") do |r|
expect(r.stdout.chomp).to eq('1')
end
end
Expand All @@ -96,7 +96,7 @@ class { 'mongodb::server': }
end

it 'creates the user' do
shell("mongo testdb --quiet --eval 'db.auth(\"testuser\",\"passw0rd\")'") do |r|
shell("mongosh testdb --quiet --eval 'db.auth(\"testuser\",\"passw0rd\")'") do |r|
expect(r.stdout.chomp).to eq('1')
end
end
Expand Down Expand Up @@ -130,25 +130,25 @@ class { 'mongodb::server': }
end

it 'allows the testuser' do
shell("mongo testdb --quiet --eval 'db.auth(\"testuser\",\"passw0rd\")'") do |r|
shell("mongosh testdb --quiet --eval 'db.auth(\"testuser\",\"passw0rd\")'") do |r|
expect(r.stdout.chomp).to eq('1')
end
end

it 'assigns roles to testuser' do
shell("mongo testdb --quiet --eval 'db.auth(\"testuser\",\"passw0rd\"); db.getUser(\"testuser\")[\"roles\"].forEach(function(role){print(role.role + \"@\" + role.db)})'") do |r|
shell("mongosh testdb --quiet --eval 'db.auth(\"testuser\",\"passw0rd\"); db.getUser(\"testuser\")[\"roles\"].forEach(function(role){print(role.role + \"@\" + role.db)})'") do |r|
expect(r.stdout.split(%r{\n})).to contain_exactly('readWrite@testdb', 'dbAdmin@testdb')
end
end

it 'allows the second user to connect to its default database' do
shell("mongo testdb2 --quiet --eval 'db.auth(\"testuser2\",\"passw0rd\")'") do |r|
shell("mongosh testdb2 --quiet --eval 'db.auth(\"testuser2\",\"passw0rd\")'") do |r|
expect(r.stdout.chomp).to eq('1')
end
end

it 'assigns roles to testuser2' do
shell("mongo testdb2 --quiet --eval 'db.auth(\"testuser2\",\"passw0rd\"); db.getUser(\"testuser2\")[\"roles\"].forEach(function(role){print(role.role + \"@\" + role.db)})'") do |r|
shell("mongosh testdb2 --quiet --eval 'db.auth(\"testuser2\",\"passw0rd\"); db.getUser(\"testuser2\")[\"roles\"].forEach(function(role){print(role.role + \"@\" + role.db)})'") do |r|
expect(r.stdout.split(%r{\n})).to contain_exactly('readWrite@testdb2', 'dbAdmin@testdb2', 'readWrite@testdb', 'dbAdmin@testdb')
end
end
Expand Down

0 comments on commit 0e76831

Please sign in to comment.