Skip to content

Commit 225383a

Browse files
author
Johan De Wit
committed
[Acceptance] Use both new mongosh and mongoshrc
1 parent 37c8a5a commit 225383a

File tree

6 files changed

+29
-29
lines changed

6 files changed

+29
-29
lines changed

spec/acceptance/database_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ class { 'mongodb::server': }
2323
end
2424

2525
it 'creates the databases' do
26-
shell("mongo testdb1 --eval 'EJSON.stringify(db.getMongo().getDBs())'")
27-
shell("mongo testdb2 --eval 'EJSON.stringify(db.getMongo().getDBs())'")
26+
shell("mongosh testdb1 --eval 'EJSON.stringify(db.getMongo().getDBs())'")
27+
shell("mongsho testdb2 --eval 'EJSON.stringify(db.getMongo().getDBs())'")
2828
end
2929
end
3030

@@ -50,8 +50,8 @@ class { 'mongodb::server':
5050
end
5151

5252
it 'creates the database' do
53-
shell("mongo testdb1 --port 27018 --eval 'EJSON.stringify(db.getMongo().getDBs())'")
54-
shell("mongo testdb2 --port 27018 --eval 'EJSON.stringify(db.getMongo().getDBs())'")
53+
shell("mongosh testdb1 --port 27018 --eval 'EJSON.stringify(db.getMongo().getDBs())'")
54+
shell("mongosh testdb2 --port 27018 --eval 'EJSON.stringify(db.getMongo().getDBs())'")
5555
end
5656
end
5757
end

spec/acceptance/mongos_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class { 'mongodb::server':
5656
it { is_expected.to be_listening }
5757
end
5858

59-
describe command('mongo --version') do
59+
describe command('mongod --version') do
6060
its(:exit_status) { is_expected.to eq 0 }
6161
end
6262
end

spec/acceptance/replset_spec.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
describe 'mongodb_replset resource' do
77
after :all do
88
# Have to drop the DB to disable replsets for further testing
9-
on hosts, %{mongo local --verbose --eval 'db.dropDatabase()'}
9+
on hosts, %{mongosh local --verbose --eval 'db.dropDatabase()'}
1010

1111
pp = <<-EOS
1212
class { 'mongodb::globals': }
@@ -48,26 +48,26 @@ class { 'mongodb::client': }
4848
}
4949
EOS
5050
apply_manifest_on(hosts_as('master'), pp, catch_failures: true)
51-
on(hosts_as('master'), 'mongo --quiet --eval "EJSON.stringify(rs.conf())"') do |r|
51+
on(hosts_as('master'), 'mongosh --quiet --eval "EJSON.stringify(rs.conf())"') do |r|
5252
expect(r.stdout).to match %r{#{hosts[0]}:27017}
5353
expect(r.stdout).to match %r{#{hosts[1]}:27017}
5454
end
5555
end
5656

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

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

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

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

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

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

197197
it 'checks the data on the slave' do
198198
sleep(10)
199-
on hosts_as('slave'), %{mongo test --verbose --eval 'load("/root/.mongoshrc.js");db.getMongo().setReadPref("primaryPreferred");EJSON.stringify(db.dummyData.findOne())'} do |r|
199+
on hosts_as('slave'), %{mongosh test --verbose --eval 'load("/root/.mongoshrc.js");db.getMongo().setReadPref("primaryPreferred");EJSON.stringify(db.dummyData.findOne())'} do |r|
200200
expect(r.stdout).to match %r{created_by_puppet}
201201
end
202202
end

spec/acceptance/server_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class { 'mongodb::server': }
5454
it { is_expected.to be_listening }
5555
end
5656

57-
describe command('mongo --version') do
57+
describe command('mongod --version') do
5858
its(:exit_status) { is_expected.to eq 0 }
5959
end
6060
end
@@ -139,24 +139,24 @@ class { 'mongodb::client': }
139139
it { is_expected.to be_listening }
140140
end
141141

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

146-
describe file('/root/.mongorc.js') do
146+
describe file('/root/.mongoshrc.js') do
147147
it { is_expected.to be_file }
148148
it { is_expected.to be_owned_by 'root' }
149149
it { is_expected.to be_grouped_into 'root' }
150150
it { is_expected.to be_mode 600 }
151151
it { is_expected.to contain 'db.auth(\'admin\', \'password\')' }
152152
end
153153

154-
describe command("mongo admin --quiet --eval \"load('/root/.mongorc.js');EJSON.stringify(db.getUser('admin')['customData'])\"") do
154+
describe command("mongosh admin --quiet --eval \"load('/root/.mongoshrc.js');EJSON.stringify(db.getUser('admin')['customData'])\"") do
155155
its(:exit_status) { is_expected.to eq 0 }
156156
its(:stdout) { is_expected.to match "{ \"createdBy\" : \"Puppet Mongodb_user['User admin on db admin']\" }\n" }
157157
end
158158

159-
describe command('mongo --version') do
159+
describe command('mongod --version') do
160160
its(:exit_status) { is_expected.to eq 0 }
161161
end
162162
end

spec/acceptance/sharding_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class { 'mongodb::client': }
4646
EOS
4747

4848
apply_manifest_on(hosts_as('router'), pp, catch_failures: true)
49-
on(hosts_as('router'), 'mongo --quiet --eval "EJSON.stringify(sh.status())"') do |r|
49+
on(hosts_as('router'), 'mongosh --quiet --eval "EJSON.stringify(sh.status())"') do |r|
5050
expect(r.stdout).to match %r{foo/shard:27018}
5151
expect(r.stdout).to match %r{foo\.toto}
5252
end

spec/acceptance/user_spec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class { 'mongodb::server': }
2222
end
2323

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

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)