Skip to content

Commit a911062

Browse files
implement prose test 9
1 parent 746af47 commit a911062

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

test/integration/mongodb-handshake/mongodb-handshake.prose.test.ts

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import { expect } from 'chai';
22
import * as sinon from 'sinon';
33

4-
import { Connection, getFAASEnv, LEGACY_HELLO_COMMAND, type MongoClient } from '../../mongodb';
4+
import {
5+
Connection,
6+
getFAASEnv,
7+
Int32,
8+
LEGACY_HELLO_COMMAND,
9+
type MongoClient
10+
} from '../../mongodb';
511
describe('Handshake Prose Tests', function () {
612
let client: MongoClient;
713

@@ -110,6 +116,49 @@ describe('Handshake Prose Tests', function () {
110116
});
111117
}
112118

119+
context('Test 9: Valid container and FaaS provider', function () {
120+
const env = [
121+
['AWS_EXECUTION_ENV', 'AWS_Lambda_java8'],
122+
['AWS_REGION', 'us-east-2'],
123+
['AWS_LAMBDA_FUNCTION_MEMORY_SIZE', '1024'],
124+
['KUBERNETES_SERVICE_HOST', '1']
125+
] as EnvironmentVariables;
126+
before(() => {
127+
for (const [key, value] of env) {
128+
process.env[key] = value;
129+
}
130+
});
131+
after(() => {
132+
for (const [key] of env) {
133+
delete process.env[key];
134+
}
135+
});
136+
137+
it('runs a hello successfully', async function () {
138+
client = this.configuration.newClient({
139+
// if the handshake is not truncated, the `hello`s fail and the client does
140+
// not connect. Lowering the server selection timeout causes the tests
141+
// to fail more quickly in that scenario.
142+
serverSelectionTimeoutMS: 3000
143+
});
144+
await client.connect();
145+
});
146+
147+
it('includes both container and FAAS provider information in the client metadata', async function () {
148+
client = this.configuration.newClient();
149+
await client.connect();
150+
expect(client.topology?.s.options.extendedMetadata).to.exist;
151+
const { env } = await client.topology.s.options.extendedMetadata;
152+
153+
expect(env).to.deep.equal({
154+
region: 'us-east-2',
155+
name: 'aws.lambda',
156+
memory_mb: new Int32(1024),
157+
container: { orchestrator: 'kubernetes' }
158+
});
159+
});
160+
});
161+
113162
context(`Test 2: Test that the driver accepts an arbitrary auth mechanism`, function () {
114163
let stubCalled = false;
115164
beforeEach(() => {

0 commit comments

Comments
 (0)