Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/service-provider-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"scripts": {
"compile-ts": "tsc -p tsconfig.json",
"prepublish": "npm run compile-ts",
"test": "mocha -r \"../../scripts/import-expansions.js\" --timeout 60000 --colors -r ts-node/register \"./src/**/*.spec.ts\"",
"test-ci": "mocha -r \"../../scripts/import-expansions.js\" --timeout 60000 -r ts-node/register \"./src/**/*.spec.ts\"",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't see these tests being run with the lerna tests, so I added the test script.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! i don't think this was intentionally left out.

"lint": "eslint \"**/*.{js,ts,tsx}\"",
"check": "npm run lint"
},
Expand Down
25 changes: 25 additions & 0 deletions packages/service-provider-core/src/connect-info.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,29 @@ describe('getConnectInfo', function() {
CMD_LINE_OPTS,
TOPOLOGY_NO_CREDENTIALS)).to.deep.equal(output);
});

it('reports correct information when an empty uri is passed', function() {
const output = {
is_atlas: false,
is_localhost: false,
server_version: '3.2.0-rc2',
mongosh_version: '0.0.6',
is_enterprise: true,
auth_type: 'LDAP',
is_data_lake: false,
dl_version: null,
is_genuine: true,
non_genuine_server_name: 'mongodb',
server_arch: 'x86_64',
node_version: process.version,
server_os: 'osx',
uri: ''
};
expect(getConnectInfo(
'',
'0.0.6',
BUILD_INFO,
CMD_LINE_OPTS,
TOPOLOGY_WITH_CREDENTIALS)).to.deep.equal(output);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,36 @@ describe('CliServiceProvider [integration]', function() {
});
});

describe('.getConnectionInfo', () => {
context('when a uri has been passed', () => {
it('returns the connection\'s info', async() => {
const instance = new CliServiceProvider(client, connectionString);
const connectionInfo = await instance.getConnectionInfo();

expect(Object.keys(connectionInfo)).to.deep.equal([
'buildInfo',
'topology',
'extraInfo'
]);
expect(connectionInfo.buildInfo.version.length > 1);
});
});

context('when the optional uri has not been passed', () => {
it('returns the connection\'s info', async() => {
const instance = new CliServiceProvider(client);
const connectionInfo = await instance.getConnectionInfo();

expect(Object.keys(connectionInfo)).to.deep.equal([
'buildInfo',
'topology',
'extraInfo'
]);
expect(connectionInfo.buildInfo.version.length > 1);
});
});
});

describe('#aggregate', () => {
context('when running against a collection', () => {
let result;
Expand Down
6 changes: 4 additions & 2 deletions packages/service-provider-server/src/cli-service-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class CliServiceProvider implements ServiceProvider {
}

private readonly mongoClient: MongoClient;
private readonly uri: string;
private readonly uri?: string;

/**
* Instantiate a new CliServiceProvider with the Node driver's connected
Expand Down Expand Up @@ -112,13 +112,15 @@ class CliServiceProvider implements ServiceProvider {
// eslint-disable-next-line no-empty
} catch (e) {
}

const connectInfo = getConnectInfo(
this.uri,
this.uri ? this.uri : '',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should perhaps add a test for an empty uri in service-provider-core/src/connect-info.spec.ts, just to make sure the rest of the information from this function comes out ok.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call - added a test. I also noticed we didn't have a test script in the service-provider-core package. Is that intended? I added one, commented below.

version,
buildInfo,
cmdLineOpts,
topology
);

return {
buildInfo: buildInfo,
topology: topology,
Expand Down