From bbc88317149a3d86c50ccfd98092d5bfb77a104e Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Tue, 23 Aug 2022 00:04:12 +0000 Subject: [PATCH] fix: better support for fallback mode (#1694) - [ ] Regenerate this pull request now. PiperOrigin-RevId: 468790263 Source-Link: https://github.com/googleapis/googleapis/commit/873ab456273d105245df0fb82a6c17a814553b80 Source-Link: https://github.com/googleapis/googleapis-gen/commit/cb6f37aeff2a3472e40a7bbace8c67d75e24bee5 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiY2I2ZjM3YWVmZjJhMzQ3MmU0MGE3YmJhY2U4YzY3ZDc1ZTI0YmVlNSJ9 --- src/v1/database_admin_client.ts | 34 +++---- src/v1/instance_admin_client.ts | 16 ++-- src/v1/spanner_client.ts | 8 +- test/gapic_database_admin_v1.ts | 158 ++++++++++++++++---------------- test/gapic_instance_admin_v1.ts | 158 ++++++++++++++++---------------- test/gapic_spanner_v1.ts | 156 +++++++++++++++---------------- 6 files changed, 270 insertions(+), 260 deletions(-) diff --git a/src/v1/database_admin_client.ts b/src/v1/database_admin_client.ts index d0e6f24de..2cc7898be 100644 --- a/src/v1/database_admin_client.ts +++ b/src/v1/database_admin_client.ts @@ -30,7 +30,6 @@ import { } from 'google-gax'; import {Transform} from 'stream'; -import {RequestType} from 'google-gax/build/src/apitypes'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); /** @@ -430,7 +429,8 @@ export class DatabaseAdminClient { const apiCall = this._gaxModule.createApiCall( callPromise, this._defaults[methodName], - descriptor + descriptor, + this._opts.fallback ); this.innerApiCalls[methodName] = apiCall; @@ -1518,7 +1518,7 @@ export class DatabaseAdminClient { const decodeOperation = new gax.Operation( operation, this.descriptors.longrunning.createDatabase, - gax.createDefaultBackoffSettings() + this._gaxModule.createDefaultBackoffSettings() ); return decodeOperation as LROperation< protos.google.spanner.admin.database.v1.Database, @@ -1683,7 +1683,7 @@ export class DatabaseAdminClient { const decodeOperation = new gax.Operation( operation, this.descriptors.longrunning.updateDatabaseDdl, - gax.createDefaultBackoffSettings() + this._gaxModule.createDefaultBackoffSettings() ); return decodeOperation as LROperation< protos.google.protobuf.Empty, @@ -1848,7 +1848,7 @@ export class DatabaseAdminClient { const decodeOperation = new gax.Operation( operation, this.descriptors.longrunning.createBackup, - gax.createDefaultBackoffSettings() + this._gaxModule.createDefaultBackoffSettings() ); return decodeOperation as LROperation< protos.google.spanner.admin.database.v1.Backup, @@ -2020,7 +2020,7 @@ export class DatabaseAdminClient { const decodeOperation = new gax.Operation( operation, this.descriptors.longrunning.copyBackup, - gax.createDefaultBackoffSettings() + this._gaxModule.createDefaultBackoffSettings() ); return decodeOperation as LROperation< protos.google.spanner.admin.database.v1.Backup, @@ -2192,7 +2192,7 @@ export class DatabaseAdminClient { const decodeOperation = new gax.Operation( operation, this.descriptors.longrunning.restoreDatabase, - gax.createDefaultBackoffSettings() + this._gaxModule.createDefaultBackoffSettings() ); return decodeOperation as LROperation< protos.google.spanner.admin.database.v1.Database, @@ -2344,7 +2344,7 @@ export class DatabaseAdminClient { const callSettings = defaultCallSettings.merge(options); this.initialize(); return this.descriptors.page.listDatabases.createStream( - this.innerApiCalls.listDatabases as gax.GaxCall, + this.innerApiCalls.listDatabases as GaxCall, request, callSettings ); @@ -2396,7 +2396,7 @@ export class DatabaseAdminClient { this.initialize(); return this.descriptors.page.listDatabases.asyncIterate( this.innerApiCalls['listDatabases'] as GaxCall, - request as unknown as RequestType, + request as {}, callSettings ) as AsyncIterable; } @@ -2621,7 +2621,7 @@ export class DatabaseAdminClient { const callSettings = defaultCallSettings.merge(options); this.initialize(); return this.descriptors.page.listBackups.createStream( - this.innerApiCalls.listBackups as gax.GaxCall, + this.innerApiCalls.listBackups as GaxCall, request, callSettings ); @@ -2710,7 +2710,7 @@ export class DatabaseAdminClient { this.initialize(); return this.descriptors.page.listBackups.asyncIterate( this.innerApiCalls['listBackups'] as GaxCall, - request as unknown as RequestType, + request as {}, callSettings ) as AsyncIterable; } @@ -2958,7 +2958,7 @@ export class DatabaseAdminClient { const callSettings = defaultCallSettings.merge(options); this.initialize(); return this.descriptors.page.listDatabaseOperations.createStream( - this.innerApiCalls.listDatabaseOperations as gax.GaxCall, + this.innerApiCalls.listDatabaseOperations as GaxCall, request, callSettings ); @@ -3054,7 +3054,7 @@ export class DatabaseAdminClient { this.initialize(); return this.descriptors.page.listDatabaseOperations.asyncIterate( this.innerApiCalls['listDatabaseOperations'] as GaxCall, - request as unknown as RequestType, + request as {}, callSettings ) as AsyncIterable; } @@ -3348,7 +3348,7 @@ export class DatabaseAdminClient { const callSettings = defaultCallSettings.merge(options); this.initialize(); return this.descriptors.page.listBackupOperations.createStream( - this.innerApiCalls.listBackupOperations as gax.GaxCall, + this.innerApiCalls.listBackupOperations as GaxCall, request, callSettings ); @@ -3468,7 +3468,7 @@ export class DatabaseAdminClient { this.initialize(); return this.descriptors.page.listBackupOperations.asyncIterate( this.innerApiCalls['listBackupOperations'] as GaxCall, - request as unknown as RequestType, + request as {}, callSettings ) as AsyncIterable; } @@ -3619,7 +3619,7 @@ export class DatabaseAdminClient { const callSettings = defaultCallSettings.merge(options); this.initialize(); return this.descriptors.page.listDatabaseRoles.createStream( - this.innerApiCalls.listDatabaseRoles as gax.GaxCall, + this.innerApiCalls.listDatabaseRoles as GaxCall, request, callSettings ); @@ -3672,7 +3672,7 @@ export class DatabaseAdminClient { this.initialize(); return this.descriptors.page.listDatabaseRoles.asyncIterate( this.innerApiCalls['listDatabaseRoles'] as GaxCall, - request as unknown as RequestType, + request as {}, callSettings ) as AsyncIterable; } diff --git a/src/v1/instance_admin_client.ts b/src/v1/instance_admin_client.ts index c35456eb2..d2eb5b89f 100644 --- a/src/v1/instance_admin_client.ts +++ b/src/v1/instance_admin_client.ts @@ -30,7 +30,6 @@ import { } from 'google-gax'; import {Transform} from 'stream'; -import {RequestType} from 'google-gax/build/src/apitypes'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); /** @@ -366,7 +365,8 @@ export class InstanceAdminClient { const apiCall = this._gaxModule.createApiCall( callPromise, this._defaults[methodName], - descriptor + descriptor, + this._opts.fallback ); this.innerApiCalls[methodName] = apiCall; @@ -1189,7 +1189,7 @@ export class InstanceAdminClient { const decodeOperation = new gax.Operation( operation, this.descriptors.longrunning.createInstance, - gax.createDefaultBackoffSettings() + this._gaxModule.createDefaultBackoffSettings() ); return decodeOperation as LROperation< protos.google.spanner.admin.instance.v1.Instance, @@ -1371,7 +1371,7 @@ export class InstanceAdminClient { const decodeOperation = new gax.Operation( operation, this.descriptors.longrunning.updateInstance, - gax.createDefaultBackoffSettings() + this._gaxModule.createDefaultBackoffSettings() ); return decodeOperation as LROperation< protos.google.spanner.admin.instance.v1.Instance, @@ -1525,7 +1525,7 @@ export class InstanceAdminClient { const callSettings = defaultCallSettings.merge(options); this.initialize(); return this.descriptors.page.listInstanceConfigs.createStream( - this.innerApiCalls.listInstanceConfigs as gax.GaxCall, + this.innerApiCalls.listInstanceConfigs as GaxCall, request, callSettings ); @@ -1578,7 +1578,7 @@ export class InstanceAdminClient { this.initialize(); return this.descriptors.page.listInstanceConfigs.asyncIterate( this.innerApiCalls['listInstanceConfigs'] as GaxCall, - request as unknown as RequestType, + request as {}, callSettings ) as AsyncIterable; } @@ -1767,7 +1767,7 @@ export class InstanceAdminClient { const callSettings = defaultCallSettings.merge(options); this.initialize(); return this.descriptors.page.listInstances.createStream( - this.innerApiCalls.listInstances as gax.GaxCall, + this.innerApiCalls.listInstances as GaxCall, request, callSettings ); @@ -1839,7 +1839,7 @@ export class InstanceAdminClient { this.initialize(); return this.descriptors.page.listInstances.asyncIterate( this.innerApiCalls['listInstances'] as GaxCall, - request as unknown as RequestType, + request as {}, callSettings ) as AsyncIterable; } diff --git a/src/v1/spanner_client.ts b/src/v1/spanner_client.ts index 6a7c93112..a6189ce24 100644 --- a/src/v1/spanner_client.ts +++ b/src/v1/spanner_client.ts @@ -29,7 +29,6 @@ import { } from 'google-gax'; import {Transform} from 'stream'; -import {RequestType} from 'google-gax/build/src/apitypes'; import {PassThrough} from 'stream'; import * as protos from '../../protos/protos'; import jsonProtos = require('../../protos/protos.json'); @@ -298,7 +297,8 @@ export class SpannerClient { const apiCall = this._gaxModule.createApiCall( callPromise, this._defaults[methodName], - descriptor + descriptor, + this._opts.fallback ); this.innerApiCalls[methodName] = apiCall; @@ -2013,7 +2013,7 @@ export class SpannerClient { const callSettings = defaultCallSettings.merge(options); this.initialize(); return this.descriptors.page.listSessions.createStream( - this.innerApiCalls.listSessions as gax.GaxCall, + this.innerApiCalls.listSessions as GaxCall, request, callSettings ); @@ -2073,7 +2073,7 @@ export class SpannerClient { this.initialize(); return this.descriptors.page.listSessions.asyncIterate( this.innerApiCalls['listSessions'] as GaxCall, - request as unknown as RequestType, + request as {}, callSettings ) as AsyncIterable; } diff --git a/test/gapic_database_admin_v1.ts b/test/gapic_database_admin_v1.ts index 560c24b3a..94e2f9f8d 100644 --- a/test/gapic_database_admin_v1.ts +++ b/test/gapic_database_admin_v1.ts @@ -145,99 +145,103 @@ function stubAsyncIterationCall( } describe('v1.DatabaseAdminClient', () => { - it('has servicePath', () => { - const servicePath = databaseadminModule.v1.DatabaseAdminClient.servicePath; - assert(servicePath); - }); - - it('has apiEndpoint', () => { - const apiEndpoint = databaseadminModule.v1.DatabaseAdminClient.apiEndpoint; - assert(apiEndpoint); - }); - - it('has port', () => { - const port = databaseadminModule.v1.DatabaseAdminClient.port; - assert(port); - assert(typeof port === 'number'); - }); + describe('Common methods', () => { + it('has servicePath', () => { + const servicePath = + databaseadminModule.v1.DatabaseAdminClient.servicePath; + assert(servicePath); + }); - it('should create a client with no option', () => { - const client = new databaseadminModule.v1.DatabaseAdminClient(); - assert(client); - }); + it('has apiEndpoint', () => { + const apiEndpoint = + databaseadminModule.v1.DatabaseAdminClient.apiEndpoint; + assert(apiEndpoint); + }); - it('should create a client with gRPC fallback', () => { - const client = new databaseadminModule.v1.DatabaseAdminClient({ - fallback: true, + it('has port', () => { + const port = databaseadminModule.v1.DatabaseAdminClient.port; + assert(port); + assert(typeof port === 'number'); }); - assert(client); - }); - it('has initialize method and supports deferred initialization', async () => { - const client = new databaseadminModule.v1.DatabaseAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', + it('should create a client with no option', () => { + const client = new databaseadminModule.v1.DatabaseAdminClient(); + assert(client); }); - assert.strictEqual(client.databaseAdminStub, undefined); - await client.initialize(); - assert(client.databaseAdminStub); - }); - it('has close method for the initialized client', done => { - const client = new databaseadminModule.v1.DatabaseAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', + it('should create a client with gRPC fallback', () => { + const client = new databaseadminModule.v1.DatabaseAdminClient({ + fallback: true, + }); + assert(client); }); - client.initialize(); - assert(client.databaseAdminStub); - client.close().then(() => { - done(); + + it('has initialize method and supports deferred initialization', async () => { + const client = new databaseadminModule.v1.DatabaseAdminClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.databaseAdminStub, undefined); + await client.initialize(); + assert(client.databaseAdminStub); }); - }); - it('has close method for the non-initialized client', done => { - const client = new databaseadminModule.v1.DatabaseAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', + it('has close method for the initialized client', done => { + const client = new databaseadminModule.v1.DatabaseAdminClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + assert(client.databaseAdminStub); + client.close().then(() => { + done(); + }); }); - assert.strictEqual(client.databaseAdminStub, undefined); - client.close().then(() => { - done(); + + it('has close method for the non-initialized client', done => { + const client = new databaseadminModule.v1.DatabaseAdminClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.databaseAdminStub, undefined); + client.close().then(() => { + done(); + }); }); - }); - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new databaseadminModule.v1.DatabaseAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new databaseadminModule.v1.DatabaseAdminClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); + const result = await client.getProjectId(); + assert.strictEqual(result, fakeProjectId); + assert((client.auth.getProjectId as SinonStub).calledWithExactly()); }); - client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); - const result = await client.getProjectId(); - assert.strictEqual(result, fakeProjectId); - assert((client.auth.getProjectId as SinonStub).calledWithExactly()); - }); - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new databaseadminModule.v1.DatabaseAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.auth.getProjectId = sinon - .stub() - .callsArgWith(0, null, fakeProjectId); - const promise = new Promise((resolve, reject) => { - client.getProjectId((err?: Error | null, projectId?: string | null) => { - if (err) { - reject(err); - } else { - resolve(projectId); - } + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new databaseadminModule.v1.DatabaseAdminClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.auth.getProjectId = sinon + .stub() + .callsArgWith(0, null, fakeProjectId); + const promise = new Promise((resolve, reject) => { + client.getProjectId((err?: Error | null, projectId?: string | null) => { + if (err) { + reject(err); + } else { + resolve(projectId); + } + }); }); + const result = await promise; + assert.strictEqual(result, fakeProjectId); }); - const result = await promise; - assert.strictEqual(result, fakeProjectId); }); describe('getDatabase', () => { diff --git a/test/gapic_instance_admin_v1.ts b/test/gapic_instance_admin_v1.ts index b967e6326..d56ea7348 100644 --- a/test/gapic_instance_admin_v1.ts +++ b/test/gapic_instance_admin_v1.ts @@ -145,99 +145,103 @@ function stubAsyncIterationCall( } describe('v1.InstanceAdminClient', () => { - it('has servicePath', () => { - const servicePath = instanceadminModule.v1.InstanceAdminClient.servicePath; - assert(servicePath); - }); - - it('has apiEndpoint', () => { - const apiEndpoint = instanceadminModule.v1.InstanceAdminClient.apiEndpoint; - assert(apiEndpoint); - }); - - it('has port', () => { - const port = instanceadminModule.v1.InstanceAdminClient.port; - assert(port); - assert(typeof port === 'number'); - }); + describe('Common methods', () => { + it('has servicePath', () => { + const servicePath = + instanceadminModule.v1.InstanceAdminClient.servicePath; + assert(servicePath); + }); - it('should create a client with no option', () => { - const client = new instanceadminModule.v1.InstanceAdminClient(); - assert(client); - }); + it('has apiEndpoint', () => { + const apiEndpoint = + instanceadminModule.v1.InstanceAdminClient.apiEndpoint; + assert(apiEndpoint); + }); - it('should create a client with gRPC fallback', () => { - const client = new instanceadminModule.v1.InstanceAdminClient({ - fallback: true, + it('has port', () => { + const port = instanceadminModule.v1.InstanceAdminClient.port; + assert(port); + assert(typeof port === 'number'); }); - assert(client); - }); - it('has initialize method and supports deferred initialization', async () => { - const client = new instanceadminModule.v1.InstanceAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', + it('should create a client with no option', () => { + const client = new instanceadminModule.v1.InstanceAdminClient(); + assert(client); }); - assert.strictEqual(client.instanceAdminStub, undefined); - await client.initialize(); - assert(client.instanceAdminStub); - }); - it('has close method for the initialized client', done => { - const client = new instanceadminModule.v1.InstanceAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', + it('should create a client with gRPC fallback', () => { + const client = new instanceadminModule.v1.InstanceAdminClient({ + fallback: true, + }); + assert(client); }); - client.initialize(); - assert(client.instanceAdminStub); - client.close().then(() => { - done(); + + it('has initialize method and supports deferred initialization', async () => { + const client = new instanceadminModule.v1.InstanceAdminClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.instanceAdminStub, undefined); + await client.initialize(); + assert(client.instanceAdminStub); }); - }); - it('has close method for the non-initialized client', done => { - const client = new instanceadminModule.v1.InstanceAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', + it('has close method for the initialized client', done => { + const client = new instanceadminModule.v1.InstanceAdminClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + assert(client.instanceAdminStub); + client.close().then(() => { + done(); + }); }); - assert.strictEqual(client.instanceAdminStub, undefined); - client.close().then(() => { - done(); + + it('has close method for the non-initialized client', done => { + const client = new instanceadminModule.v1.InstanceAdminClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.instanceAdminStub, undefined); + client.close().then(() => { + done(); + }); }); - }); - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new instanceadminModule.v1.InstanceAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new instanceadminModule.v1.InstanceAdminClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); + const result = await client.getProjectId(); + assert.strictEqual(result, fakeProjectId); + assert((client.auth.getProjectId as SinonStub).calledWithExactly()); }); - client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); - const result = await client.getProjectId(); - assert.strictEqual(result, fakeProjectId); - assert((client.auth.getProjectId as SinonStub).calledWithExactly()); - }); - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new instanceadminModule.v1.InstanceAdminClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.auth.getProjectId = sinon - .stub() - .callsArgWith(0, null, fakeProjectId); - const promise = new Promise((resolve, reject) => { - client.getProjectId((err?: Error | null, projectId?: string | null) => { - if (err) { - reject(err); - } else { - resolve(projectId); - } + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new instanceadminModule.v1.InstanceAdminClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.auth.getProjectId = sinon + .stub() + .callsArgWith(0, null, fakeProjectId); + const promise = new Promise((resolve, reject) => { + client.getProjectId((err?: Error | null, projectId?: string | null) => { + if (err) { + reject(err); + } else { + resolve(projectId); + } + }); }); + const result = await promise; + assert.strictEqual(result, fakeProjectId); }); - const result = await promise; - assert.strictEqual(result, fakeProjectId); }); describe('getInstanceConfig', () => { diff --git a/test/gapic_spanner_v1.ts b/test/gapic_spanner_v1.ts index 7c07645a0..e7f142eda 100644 --- a/test/gapic_spanner_v1.ts +++ b/test/gapic_spanner_v1.ts @@ -134,99 +134,101 @@ function stubAsyncIterationCall( } describe('v1.SpannerClient', () => { - it('has servicePath', () => { - const servicePath = spannerModule.v1.SpannerClient.servicePath; - assert(servicePath); - }); - - it('has apiEndpoint', () => { - const apiEndpoint = spannerModule.v1.SpannerClient.apiEndpoint; - assert(apiEndpoint); - }); - - it('has port', () => { - const port = spannerModule.v1.SpannerClient.port; - assert(port); - assert(typeof port === 'number'); - }); + describe('Common methods', () => { + it('has servicePath', () => { + const servicePath = spannerModule.v1.SpannerClient.servicePath; + assert(servicePath); + }); - it('should create a client with no option', () => { - const client = new spannerModule.v1.SpannerClient(); - assert(client); - }); + it('has apiEndpoint', () => { + const apiEndpoint = spannerModule.v1.SpannerClient.apiEndpoint; + assert(apiEndpoint); + }); - it('should create a client with gRPC fallback', () => { - const client = new spannerModule.v1.SpannerClient({ - fallback: true, + it('has port', () => { + const port = spannerModule.v1.SpannerClient.port; + assert(port); + assert(typeof port === 'number'); }); - assert(client); - }); - it('has initialize method and supports deferred initialization', async () => { - const client = new spannerModule.v1.SpannerClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', + it('should create a client with no option', () => { + const client = new spannerModule.v1.SpannerClient(); + assert(client); }); - assert.strictEqual(client.spannerStub, undefined); - await client.initialize(); - assert(client.spannerStub); - }); - it('has close method for the initialized client', done => { - const client = new spannerModule.v1.SpannerClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', + it('should create a client with gRPC fallback', () => { + const client = new spannerModule.v1.SpannerClient({ + fallback: true, + }); + assert(client); }); - client.initialize(); - assert(client.spannerStub); - client.close().then(() => { - done(); + + it('has initialize method and supports deferred initialization', async () => { + const client = new spannerModule.v1.SpannerClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.spannerStub, undefined); + await client.initialize(); + assert(client.spannerStub); }); - }); - it('has close method for the non-initialized client', done => { - const client = new spannerModule.v1.SpannerClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', + it('has close method for the initialized client', done => { + const client = new spannerModule.v1.SpannerClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + assert(client.spannerStub); + client.close().then(() => { + done(); + }); }); - assert.strictEqual(client.spannerStub, undefined); - client.close().then(() => { - done(); + + it('has close method for the non-initialized client', done => { + const client = new spannerModule.v1.SpannerClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.spannerStub, undefined); + client.close().then(() => { + done(); + }); }); - }); - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new spannerModule.v1.SpannerClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new spannerModule.v1.SpannerClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); + const result = await client.getProjectId(); + assert.strictEqual(result, fakeProjectId); + assert((client.auth.getProjectId as SinonStub).calledWithExactly()); }); - client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); - const result = await client.getProjectId(); - assert.strictEqual(result, fakeProjectId); - assert((client.auth.getProjectId as SinonStub).calledWithExactly()); - }); - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new spannerModule.v1.SpannerClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.auth.getProjectId = sinon - .stub() - .callsArgWith(0, null, fakeProjectId); - const promise = new Promise((resolve, reject) => { - client.getProjectId((err?: Error | null, projectId?: string | null) => { - if (err) { - reject(err); - } else { - resolve(projectId); - } + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new spannerModule.v1.SpannerClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.auth.getProjectId = sinon + .stub() + .callsArgWith(0, null, fakeProjectId); + const promise = new Promise((resolve, reject) => { + client.getProjectId((err?: Error | null, projectId?: string | null) => { + if (err) { + reject(err); + } else { + resolve(projectId); + } + }); }); + const result = await promise; + assert.strictEqual(result, fakeProjectId); }); - const result = await promise; - assert.strictEqual(result, fakeProjectId); }); describe('createSession', () => {