From 8973cbcc9158b37650af2edb6015c575da1cc3ec Mon Sep 17 00:00:00 2001 From: skuruppu Date: Thu, 11 Jun 2020 13:19:59 +1000 Subject: [PATCH] fix: set instanceId to the given id (#1094) Previously if a display name was given, we were setting the instanceId to the display name. This is a bug. Fixes #1093 --- src/index.ts | 2 +- test/spanner.ts | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 3b925f18b..1d7f934f1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -368,7 +368,7 @@ class Spanner extends GrpcService { const displayName = config.displayName || formattedName.split('/').pop(); const reqOpts = { parent: 'projects/' + this.projectId, - instanceId: displayName, + instanceId: formattedName.split('/').pop(), instance: extend( { name: formattedName, diff --git a/test/spanner.ts b/test/spanner.ts index 64da1cb1b..74617e4a5 100644 --- a/test/spanner.ts +++ b/test/spanner.ts @@ -2283,6 +2283,30 @@ describe('Spanner with mock server', () => { assert.strictEqual(createdInstance.nodeCount, 10); }); + it('should create an instance with a display name', async () => { + const [createdInstance] = await spanner + .createInstance('new-instance', { + config: 'test-instance-config', + nodes: 10, + displayName: 'some new instance', + }) + .then(data => { + const operation = data[1]; + return operation.promise() as Promise< + [Instance, CreateInstanceMetadata, object] + >; + }) + .then(response => { + return response; + }); + assert.strictEqual( + createdInstance.name, + `projects/${spanner.projectId}/instances/new-instance` + ); + assert.strictEqual(createdInstance.nodeCount, 10); + assert.strictEqual(createdInstance.displayName, 'some new instance'); + }); + it('should create an instance using a callback', done => { spanner.createInstance( 'new-instance',