From 5947d022c958fee21f12e3305a8cb458f5bf86b6 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Wed, 19 May 2021 12:18:26 +0200 Subject: [PATCH] feat(cli-repl): include API version in greeting message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is mostly so that when `--apiStrict` is used, we’ll show the API version instead of just `Using MongoDB: undefined` (which fits, because in that case the API version effectively fills the role the server version currently has). --- packages/cli-repl/src/mongosh-repl.ts | 6 +++++- packages/cli-repl/test/e2e.spec.ts | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/cli-repl/src/mongosh-repl.ts b/packages/cli-repl/src/mongosh-repl.ts index 24799f2b1e..e6258715d2 100644 --- a/packages/cli-repl/src/mongosh-repl.ts +++ b/packages/cli-repl/src/mongosh-repl.ts @@ -129,7 +129,11 @@ class MongoshNodeRepl implements EvaluationListener { internalState.setEvaluationListener(this); await internalState.fetchConnectionInfo(); - const mongodVersion = internalState.connectionInfo.buildInfo?.version; + let mongodVersion = internalState.connectionInfo.buildInfo?.version; + const apiVersion = serviceProvider.getRawClient()?.serverApi?.version; + if (apiVersion) { + mongodVersion = (mongodVersion ? mongodVersion + ' ' : '') + `(API Version ${apiVersion})`; + } await this.greet(mongodVersion); await this.printStartupLog(internalState); diff --git a/packages/cli-repl/test/e2e.spec.ts b/packages/cli-repl/test/e2e.spec.ts index ddbff7f1ed..229db4ba19 100644 --- a/packages/cli-repl/test/e2e.spec.ts +++ b/packages/cli-repl/test/e2e.spec.ts @@ -906,6 +906,22 @@ describe('e2e', function() { `${await testServer.connectionString()}/${dbName}`, '--apiVersion', '1' ] }); await shell.waitForPrompt(); + shell.assertContainsOutput('(API Version 1)'); + expect(await shell.executeLine('db.coll.find().toArray()')) + .to.include('[]'); + shell.assertNoErrors(); + }); + + it('can specify an API version and strict mode', async function() { + // Disable this until https://jira.mongodb.org/browse/NODE-3183 + // is done because the server has started requiring hello instead of + // isMaster. + return this.skip(); + const shell = TestShell.start({ args: [ + `${await testServer.connectionString()}/${dbName}`, '--apiVersion', '1', '--apiStrict', '--apiDeprecationErrors' + ] }); + await shell.waitForPrompt(); + shell.assertContainsOutput('(API Version 1)'); expect(await shell.executeLine('db.coll.find().toArray()')) .to.include('[]'); shell.assertNoErrors();