Skip to content

Commit 9699ea2

Browse files
committed
fix: tests
1 parent 59ef773 commit 9699ea2

File tree

3 files changed

+47
-45
lines changed

3 files changed

+47
-45
lines changed

src/cmap/handshake/faas_env.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ export function getFAASEnv(): Map<string, string | Int32> | null {
3333
faasEnv.set('region', AWS_REGION);
3434
}
3535

36-
const memory_mb = Number(AWS_LAMBDA_FUNCTION_MEMORY_SIZE);
37-
if (Number.isInteger(memory_mb)) {
38-
faasEnv.set('memory_mb', new Int32(memory_mb));
36+
if (
37+
AWS_LAMBDA_FUNCTION_MEMORY_SIZE.length > 0 &&
38+
Number.isInteger(+AWS_LAMBDA_FUNCTION_MEMORY_SIZE)
39+
) {
40+
faasEnv.set('memory_mb', new Int32(AWS_LAMBDA_FUNCTION_MEMORY_SIZE));
3941
}
4042

4143
return faasEnv;
@@ -49,14 +51,12 @@ export function getFAASEnv(): Map<string, string | Int32> | null {
4951
faasEnv.set('region', FUNCTION_REGION);
5052
}
5153

52-
const memory_mb = Number(FUNCTION_MEMORY_MB);
53-
if (Number.isInteger(memory_mb)) {
54-
faasEnv.set('memory_mb', new Int32(memory_mb));
54+
if (FUNCTION_MEMORY_MB.length > 0 && Number.isInteger(+FUNCTION_MEMORY_MB)) {
55+
faasEnv.set('memory_mb', new Int32(FUNCTION_MEMORY_MB));
5556
}
5657

57-
const timeout_sec = Number(FUNCTION_TIMEOUT_SEC);
58-
if (Number.isInteger(timeout_sec)) {
59-
faasEnv.set('timeout_sec', new Int32(timeout_sec));
58+
if (FUNCTION_TIMEOUT_SEC.length > 0 && Number.isInteger(+FUNCTION_TIMEOUT_SEC)) {
59+
faasEnv.set('timeout_sec', new Int32(FUNCTION_TIMEOUT_SEC));
6060
}
6161

6262
return faasEnv;

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

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
import { expect } from 'chai';
2-
import * as sinon from 'sinon';
32

4-
import {
5-
Connection,
6-
getFAASEnv,
7-
LEGACY_HELLO_COMMAND,
8-
MongoClient,
9-
MongoServerSelectionError
10-
} from '../../mongodb';
3+
import { getFAASEnv, MongoClient } from '../../mongodb';
114

12-
describe.only('FAAS Environment Prose Tests', function () {
5+
describe('FAAS Environment Prose Tests', function () {
136
let client: MongoClient;
147

158
afterEach(async function () {
@@ -112,31 +105,4 @@ describe.only('FAAS Environment Prose Tests', function () {
112105
});
113106
});
114107
}
115-
116-
context('when hello is too large', () => {
117-
before(() => {
118-
sinon.stub(Connection.prototype, 'command').callsFake(function (ns, cmd, options, callback) {
119-
const command = Connection.prototype.command.wrappedMethod.bind(this);
120-
121-
if (cmd.hello || cmd[LEGACY_HELLO_COMMAND]) {
122-
return command(
123-
ns,
124-
{ ...cmd, client: { driver: { name: 'a'.repeat(1000) } } },
125-
options,
126-
callback
127-
);
128-
}
129-
return command(ns, cmd, options, callback);
130-
});
131-
});
132-
133-
after(() => sinon.restore());
134-
135-
it('client fails to connect with an error relating to size', async function () {
136-
client = this.configuration.newClient({ serverSelectionTimeoutMS: 2000 });
137-
const error = await client.connect().catch(error => error);
138-
expect(error).to.be.instanceOf(MongoServerSelectionError);
139-
expect(error).to.match(/client metadata document must be less/);
140-
});
141-
});
142108
});
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { expect } from 'chai';
2+
import * as sinon from 'sinon';
3+
4+
import { Connection, LEGACY_HELLO_COMMAND, MongoServerSelectionError } from '../../mongodb';
5+
6+
describe('MongoDB Handshake Node tests', () => {
7+
let client;
8+
9+
context('when hello is too large', () => {
10+
before(() => {
11+
sinon.stub(Connection.prototype, 'command').callsFake(function (ns, cmd, options, callback) {
12+
// @ts-expect-error: sinon will place wrappedMethod there
13+
const command = Connection.prototype.command.wrappedMethod.bind(this);
14+
15+
if (cmd.hello || cmd[LEGACY_HELLO_COMMAND]) {
16+
return command(
17+
ns,
18+
{ ...cmd, client: { driver: { name: 'a'.repeat(1000) } } },
19+
options,
20+
callback
21+
);
22+
}
23+
return command(ns, cmd, options, callback);
24+
});
25+
});
26+
27+
after(() => sinon.restore());
28+
29+
it('client fails to connect with an error relating to size', async function () {
30+
client = this.configuration.newClient({ serverSelectionTimeoutMS: 2000 });
31+
const error = await client.connect().catch(error => error);
32+
expect(error).to.be.instanceOf(MongoServerSelectionError);
33+
expect(error).to.match(/client metadata document must be less/);
34+
});
35+
});
36+
});

0 commit comments

Comments
 (0)