Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nbbeeken committed Apr 5, 2023
1 parent 4be609f commit 70da1d6
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 45 deletions.
18 changes: 9 additions & 9 deletions src/cmap/handshake/faas_env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ export function getFAASEnv(): Map<string, string | Int32> | null {
faasEnv.set('region', AWS_REGION);
}

const memory_mb = Number(AWS_LAMBDA_FUNCTION_MEMORY_SIZE);
if (Number.isInteger(memory_mb)) {
faasEnv.set('memory_mb', new Int32(memory_mb));
if (
AWS_LAMBDA_FUNCTION_MEMORY_SIZE.length > 0 &&
Number.isInteger(+AWS_LAMBDA_FUNCTION_MEMORY_SIZE)
) {
faasEnv.set('memory_mb', new Int32(AWS_LAMBDA_FUNCTION_MEMORY_SIZE));
}

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

const memory_mb = Number(FUNCTION_MEMORY_MB);
if (Number.isInteger(memory_mb)) {
faasEnv.set('memory_mb', new Int32(memory_mb));
if (FUNCTION_MEMORY_MB.length > 0 && Number.isInteger(+FUNCTION_MEMORY_MB)) {
faasEnv.set('memory_mb', new Int32(FUNCTION_MEMORY_MB));
}

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

return faasEnv;
Expand Down
38 changes: 2 additions & 36 deletions test/integration/mongodb-handshake/mongodb-handshake.prose.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import { expect } from 'chai';
import * as sinon from 'sinon';

import {
Connection,
getFAASEnv,
LEGACY_HELLO_COMMAND,
MongoClient,
MongoServerSelectionError
} from '../../mongodb';
import { getFAASEnv, MongoClient } from '../../mongodb';

describe.only('FAAS Environment Prose Tests', function () {
describe('FAAS Environment Prose Tests', function () {
let client: MongoClient;

afterEach(async function () {
Expand Down Expand Up @@ -112,31 +105,4 @@ describe.only('FAAS Environment Prose Tests', function () {
});
});
}

context('when hello is too large', () => {
before(() => {
sinon.stub(Connection.prototype, 'command').callsFake(function (ns, cmd, options, callback) {
const command = Connection.prototype.command.wrappedMethod.bind(this);

if (cmd.hello || cmd[LEGACY_HELLO_COMMAND]) {
return command(
ns,
{ ...cmd, client: { driver: { name: 'a'.repeat(1000) } } },
options,
callback
);
}
return command(ns, cmd, options, callback);
});
});

after(() => sinon.restore());

it('client fails to connect with an error relating to size', async function () {
client = this.configuration.newClient({ serverSelectionTimeoutMS: 2000 });
const error = await client.connect().catch(error => error);
expect(error).to.be.instanceOf(MongoServerSelectionError);
expect(error).to.match(/client metadata document must be less/);
});
});
});
36 changes: 36 additions & 0 deletions test/integration/mongodb-handshake/mongodb-handshake.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { expect } from 'chai';
import * as sinon from 'sinon';

import { Connection, LEGACY_HELLO_COMMAND, MongoServerSelectionError } from '../../mongodb';

describe('MongoDB Handshake Node tests', () => {
let client;

context('when hello is too large', () => {
before(() => {
sinon.stub(Connection.prototype, 'command').callsFake(function (ns, cmd, options, callback) {
// @ts-expect-error: sinon will place wrappedMethod there
const command = Connection.prototype.command.wrappedMethod.bind(this);

if (cmd.hello || cmd[LEGACY_HELLO_COMMAND]) {
return command(
ns,
{ ...cmd, client: { driver: { name: 'a'.repeat(1000) } } },
options,
callback
);
}
return command(ns, cmd, options, callback);
});
});

after(() => sinon.restore());

it('client fails to connect with an error relating to size', async function () {
client = this.configuration.newClient({ serverSelectionTimeoutMS: 2000 });
const error = await client.connect().catch(error => error);
expect(error).to.be.instanceOf(MongoServerSelectionError);
expect(error).to.match(/client metadata document must be less/);
});
});
});

0 comments on commit 70da1d6

Please sign in to comment.