Skip to content

Commit ce2f446

Browse files
committed
Update tests to start shells from context
1 parent 6bb4a8e commit ce2f446

14 files changed

+190
-216
lines changed

packages/e2e-tests/test/e2e-analytics.spec.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { expect } from 'chai';
22
import { startTestCluster } from '../../../testing/integration-testing-hooks';
33
import { eventually } from '../../../testing/eventually';
4-
import { cleanTestShellsAfterEach, TestShell } from './test-shell';
54

65
describe('e2e Analytics Node', function () {
76
const replSetName = 'replicaSet';
@@ -13,8 +12,6 @@ describe('e2e Analytics Node', function () {
1312
{ args: ['--replSet', replSetName] }
1413
);
1514

16-
cleanTestShellsAfterEach();
17-
1815
before(async function () {
1916
if (process.env.MONGOSH_TEST_FORCE_API_STRICT) {
2017
return this.skip();
@@ -36,7 +33,7 @@ describe('e2e Analytics Node', function () {
3633
],
3734
};
3835

39-
const shell = TestShell.start({
36+
const shell = this.startTestShell({
4037
args: [await rs0.connectionString()],
4138
});
4239
await shell.waitForPrompt();
@@ -55,7 +52,7 @@ describe('e2e Analytics Node', function () {
5552

5653
context('without readPreference', function () {
5754
it('a direct connection ends up at primary', async function () {
58-
const shell = TestShell.start({
55+
const shell = this.startTestShell({
5956
args: [await rs0.connectionString()],
6057
});
6158
await shell.waitForPrompt();
@@ -68,13 +65,13 @@ describe('e2e Analytics Node', function () {
6865

6966
context('specifying readPreference and tags', function () {
7067
it('ends up at the ANALYTICS node', async function () {
71-
const shell = TestShell.start({
68+
const shell = this.startTestShell({
7269
args: [
7370
`${await rs0.connectionString()}?replicaSet=${replSetName}&readPreference=secondary&readPreferenceTags=nodeType:ANALYTICS`,
7471
],
7572
});
7673

77-
const directConnectionToAnalyticsShell = TestShell.start({
74+
const directConnectionToAnalyticsShell = this.startTestShell({
7875
args: [`${await rs3.connectionString()}?directConnection=true`],
7976
});
8077
await Promise.all([

packages/e2e-tests/test/e2e-auth.spec.ts

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { expect } from 'chai';
22
import type { Db, Document, MongoClientOptions } from 'mongodb';
33
import { MongoClient } from 'mongodb';
44
import { eventually } from '../../../testing/eventually';
5-
import { cleanTestShellsAfterEach, TestShell } from './test-shell';
5+
import type { TestShell } from './test-shell';
66
import {
77
skipIfApiStrict,
88
startSharedTestServer,
@@ -107,12 +107,10 @@ describe('Auth e2e', function () {
107107
let examplePrivilege2: Document;
108108

109109
describe('with regular URI', function () {
110-
cleanTestShellsAfterEach();
111-
112110
beforeEach(async function () {
113111
const connectionString = await testServer.connectionString();
114112
dbName = `test-${Date.now()}`;
115-
shell = TestShell.start({ args: [connectionString] });
113+
shell = this.startTestShell({ args: [connectionString] });
116114

117115
client = await MongoClient.connect(connectionString, {});
118116

@@ -880,7 +878,7 @@ describe('Auth e2e', function () {
880878
pathname: `/${dbName}`,
881879
}
882880
);
883-
shell = TestShell.start({ args: [authConnectionString] });
881+
shell = this.startTestShell({ args: [authConnectionString] });
884882
await shell.waitForPrompt();
885883
shell.assertNoErrors();
886884
await shell.executeLine(`use ${dbName}`);
@@ -904,7 +902,7 @@ describe('Auth e2e', function () {
904902
pathname: `/${dbName}`,
905903
}
906904
);
907-
shell = TestShell.start({ args: [authConnectionString] });
905+
shell = this.startTestShell({ args: [authConnectionString] });
908906
await shell.waitForPrompt();
909907
shell.assertNoErrors();
910908
await shell.executeLine(`use ${dbName}`);
@@ -931,7 +929,7 @@ describe('Auth e2e', function () {
931929
});
932930
it('can auth when there is -u and -p', async function () {
933931
const connectionString = await testServer.connectionString();
934-
shell = TestShell.start({
932+
shell = this.startTestShell({
935933
args: [
936934
connectionString,
937935
'-u',
@@ -966,7 +964,7 @@ describe('Auth e2e', function () {
966964
return this.skip(); // No SCRAM-SHA-1 in FIPS mode
967965
}
968966
const connectionString = await testServer.connectionString();
969-
shell = TestShell.start({
967+
shell = this.startTestShell({
970968
args: [
971969
connectionString,
972970
'-u',
@@ -990,7 +988,7 @@ describe('Auth e2e', function () {
990988
// This test is not particularly meaningful if we're using the system OpenSSL installation
991989
// and it is not properly configured for FIPS to begin with. This is the case on e.g.
992990
// Ubuntu 22.04 in evergreen CI.
993-
const preTestShell = TestShell.start({
991+
const preTestShell = this.startTestShell({
994992
args: [
995993
'--quiet',
996994
'--nodb',
@@ -1010,7 +1008,7 @@ describe('Auth e2e', function () {
10101008
}
10111009

10121010
const connectionString = await testServer.connectionString();
1013-
shell = TestShell.start({
1011+
shell = this.startTestShell({
10141012
args: [
10151013
connectionString,
10161014
'--tlsFIPSMode',
@@ -1035,7 +1033,7 @@ describe('Auth e2e', function () {
10351033
});
10361034
it('can auth with SCRAM-SHA-256', async function () {
10371035
const connectionString = await testServer.connectionString();
1038-
shell = TestShell.start({
1036+
shell = this.startTestShell({
10391037
args: [
10401038
connectionString,
10411039
'-u',
@@ -1056,7 +1054,7 @@ describe('Auth e2e', function () {
10561054
});
10571055
it('cannot auth when authenticationMechanism mismatches (sha256 -> sha1)', async function () {
10581056
const connectionString = await testServer.connectionString();
1059-
shell = TestShell.start({
1057+
shell = this.startTestShell({
10601058
args: [
10611059
connectionString,
10621060
'-u',
@@ -1077,7 +1075,7 @@ describe('Auth e2e', function () {
10771075
});
10781076
it('cannot auth when authenticationMechanism mismatches (sha1 -> sha256)', async function () {
10791077
const connectionString = await testServer.connectionString();
1080-
shell = TestShell.start({
1078+
shell = this.startTestShell({
10811079
args: [
10821080
connectionString,
10831081
'-u',
@@ -1098,7 +1096,7 @@ describe('Auth e2e', function () {
10981096
});
10991097
it('does not fail with kerberos not found for GSSAPI', async function () {
11001098
const connectionString = await testServer.connectionString();
1101-
shell = TestShell.start({
1099+
shell = this.startTestShell({
11021100
args: [
11031101
connectionString,
11041102
'-u',
@@ -1145,7 +1143,5 @@ describe('Auth e2e', function () {
11451143

11461144
await client.close();
11471145
});
1148-
1149-
cleanTestShellsAfterEach();
11501146
});
11511147
});

packages/e2e-tests/test/e2e-aws.spec.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { expect } from 'chai';
22
import { spawnSync } from 'child_process';
3-
import { cleanTestShellsAfterEach, TestShell } from './test-shell';
43

54
function assertEnvVariable(variableName: string): string {
65
if (process.env.MONGOSH_TEST_FORCE_API_STRICT) {
@@ -84,8 +83,6 @@ function getConnectionString(username?: string, password?: string): string {
8483
}
8584

8685
describe('e2e AWS AUTH', function () {
87-
cleanTestShellsAfterEach();
88-
8986
this.timeout(60_000); // AWS auth tests can take longer than the default timeout in CI
9087
let expectedAssumedRole: string;
9188

@@ -122,7 +119,7 @@ describe('e2e AWS AUTH', function () {
122119
context('without environment variables being present', function () {
123120
context('specifying explicit parameters', function () {
124121
it('connects with access key and secret', async function () {
125-
const shell = TestShell.start({
122+
const shell = this.startTestShell({
126123
args: [
127124
getConnectionString(),
128125
'--username',
@@ -142,7 +139,7 @@ describe('e2e AWS AUTH', function () {
142139

143140
it('connects with access key, secret, and session token for IAM role', async function () {
144141
const tokenDetails = generateIamSessionToken();
145-
const shell = TestShell.start({
142+
const shell = this.startTestShell({
146143
args: [
147144
getConnectionString(),
148145
'--username',
@@ -165,7 +162,7 @@ describe('e2e AWS AUTH', function () {
165162

166163
context('specifying connection string parameters', function () {
167164
it('connects with access key and secret', async function () {
168-
const shell = TestShell.start({
165+
const shell = this.startTestShell({
169166
args: [getConnectionString(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)],
170167
});
171168
const result = await shell.waitForPromptOrExit();
@@ -179,7 +176,7 @@ describe('e2e AWS AUTH', function () {
179176

180177
it('connects with access key, secret, and session token for IAM role', async function () {
181178
const tokenDetails = generateIamSessionToken();
182-
const shell = TestShell.start({
179+
const shell = this.startTestShell({
183180
args: [
184181
`${getConnectionString(
185182
tokenDetails.key,
@@ -203,7 +200,7 @@ describe('e2e AWS AUTH', function () {
203200
context('with AWS environment variables', function () {
204201
context('without any other parameters', function () {
205202
it('connects for the IAM user', async function () {
206-
const shell = TestShell.start({
203+
const shell = this.startTestShell({
207204
args: [getConnectionString()],
208205
env: {
209206
...process.env,
@@ -222,7 +219,7 @@ describe('e2e AWS AUTH', function () {
222219

223220
it('connects for the IAM role session', async function () {
224221
const tokenDetails = generateIamSessionToken();
225-
const shell = TestShell.start({
222+
const shell = this.startTestShell({
226223
args: [getConnectionString()],
227224
env: {
228225
...process.env,
@@ -243,7 +240,7 @@ describe('e2e AWS AUTH', function () {
243240

244241
context('with invalid environment but valid parameters', function () {
245242
it('connects for the IAM user', async function () {
246-
const shell = TestShell.start({
243+
const shell = this.startTestShell({
247244
args: [
248245
getConnectionString(),
249246
'--username',
@@ -268,7 +265,7 @@ describe('e2e AWS AUTH', function () {
268265

269266
it('connects for the IAM role session', async function () {
270267
const tokenDetails = generateIamSessionToken();
271-
const shell = TestShell.start({
268+
const shell = this.startTestShell({
272269
args: [
273270
getConnectionString(),
274271
'--username',

packages/e2e-tests/test/e2e-banners.spec.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@ import {
22
skipIfApiStrict,
33
startSharedTestServer,
44
} from '../../../testing/integration-testing-hooks';
5-
import { cleanTestShellsAfterEach, TestShell } from './test-shell';
5+
import type { TestShell } from './test-shell';
66

77
describe('e2e startup banners', function () {
88
skipIfApiStrict();
9-
cleanTestShellsAfterEach();
109

1110
const testServer = startSharedTestServer();
1211

1312
context('without special configuration', function () {
1413
it('shows startup warnings', async function () {
15-
const shell = TestShell.start({
14+
const shell = this.startTestShell({
1615
args: [await testServer.connectionString()],
1716
});
1817
await shell.waitForPrompt();
@@ -30,7 +29,7 @@ describe('e2e startup banners', function () {
3029
let helperShell: TestShell;
3130

3231
beforeEach(async function () {
33-
helperShell = TestShell.start({
32+
helperShell = this.startTestShell({
3433
args: [await testServer.connectionString()],
3534
});
3635
await helperShell.waitForPrompt();
@@ -47,7 +46,7 @@ describe('e2e startup banners', function () {
4746
});
4847

4948
it('shows automation notices', async function () {
50-
const shell = TestShell.start({
49+
const shell = this.startTestShell({
5150
args: [await testServer.connectionString()],
5251
});
5352
await shell.waitForPrompt();

packages/e2e-tests/test/e2e-bson.spec.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ import { expect } from 'chai';
22
import type { Db } from 'mongodb';
33
import { MongoClient } from 'mongodb';
44
import { bson } from '@mongosh/service-provider-core';
5-
import { cleanTestShellsAfterEach, TestShell } from './test-shell';
5+
import type { TestShell } from './test-shell';
66
import { startSharedTestServer } from '../../../testing/integration-testing-hooks';
77

88
describe('BSON e2e', function () {
9-
cleanTestShellsAfterEach();
10-
119
const testServer = startSharedTestServer();
1210
let db: Db;
1311
let client: MongoClient;
@@ -17,7 +15,7 @@ describe('BSON e2e', function () {
1715
beforeEach(async function () {
1816
const connectionString = await testServer.connectionString();
1917
dbName = `test-${Date.now()}`;
20-
shell = TestShell.start({ args: [connectionString] });
18+
shell = this.startTestShell({ args: [connectionString] });
2119

2220
client = await MongoClient.connect(connectionString, {});
2321

0 commit comments

Comments
 (0)